11 Aralık 2022 Pazar

spotless plugin

Giriş
goal listesi şöyle
1. check
2. apply

check goal
Eğer hata varsa yapılandırma (build) başarısız olur. Şöyle yaparız
mvn spotless:check

apply goal
Kodu otomatik olarak düzeltir. Açıklaması şöyle. Sonra kodu commit'lemek gerekir.
In contrast to check goal the apply goal is not verbose at all. It just simply tells us if formatting was done or not. The main change we can observe are the changes in source code.
Örnek
Şöyle yaparız
<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>format</id>
      <phase>process-sources</phase>
      <goals>
        <goal>check</goal>
        <goal>apply</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Şöyle yaparız
mvn spotless:apply

Formatlama
Formatlama için şunlar kullanılabilir
- prettier
- google-java-format
- eclipse jdt
- palantir-java-format
- markdown
palantir
Örnek
Şöyle yaparız
<java>
  <toggleOffOn/>
  <importOrder/>
  <removeUnusedImports/>
  <palantirJavaFormat>
    <version>2.27.0</version>
  </palantirJavaFormat>
  <indent>
    <spaces>true</spaces>
    <spacesPerTab>4</spacesPerTab>
  </indent>

  <formatAnnotations/>
</java>
google-java-format Format
Örnek
Şöyle yaparız
<plugin>
<groupId>com.diffplug.spotless</groupId> <artifactId>spotless-maven-plugin</artifactId> <version>2.9.0</version> <configuration> <java> <includes> <include>src/main/java/**/*.java</include> <include>src/test/java/**/*.java</include> </includes> <googleJavaFormat> <version>1.15.0</version> <style>GOOGLE</style> </googleJavaFormat> </java> </configuration> </plugin>
prettier Format
Açıklaması şöyle
Configurations like palantirJavaFormat and prettier have their own sections. 
Örnek
Açıklaması şöyle
For example, you can configure prettier to use a separate configuration file like this:
Şöyle yaparız
<prettier>
    <version>2.4.1</version>
    <configFile>${project.basedir}/.prettierrc</configFile>
</prettier>

Örnek
Şöyle yaparız
<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <version>2.25.0</version>
  <configuration>
    <formats>
      <!-- prettier with java-plugin -->
      <format>
        <includes>
          <include>src/*/java/**/*.java</include>
        </includes>

        <prettier>
          <devDependencies>
            <prettier>2.0.5</prettier>
            <prettier-plugin-java>0.8.0</prettier-plugin-java>
          </devDependencies>
          <config>
            <tabWidth>4</tabWidth>
            <parser>java</parser>
          </config>
        </prettier>
      </format>
    </formats>
  </configuration>
  <executions>
    <execution>
      <phase>verify</phase>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
</plugin>
markdown Format
Şöyle yaparız
<markdown>
  <includes> <!-- You have to set the target manually -->
    <include>**/*.md</include>
  </includes>
  <flexmark/>
</markdown>
POM Format
Şöyle yaparız
<pom>
    <includes>
        <include>pom.xml</include>
    </includes>
    <sortPom>
        <encoding>UTF-8</encoding>
        <keepBlankLines>true</keepBlankLines>
        <nrOfIndentSpace>4</nrOfIndentSpace>
        <indentBlankLines>false</indentBlankLines>
        <indentSchemaLocation>true</indentSchemaLocation>
        <expandEmptyElements>false</expandEmptyElements>
        <sortProperties>true</sortProperties>
    </sortPom>
</pom>
Tamamı için şöyle yaparız
<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <configuration>
    <java>
      <toggleOffOn/>
      <importOrder/>
      <removeUnusedImports/>
      <palantirJavaFormat>
        <version>2.27.0</version>
      </palantirJavaFormat>
      <indent>
        <spaces>true</spaces>
        <spacesPerTab>4</spacesPerTab>
      </indent>

      <formatAnnotations/>
    </java>
    <markdown>
      <includes>
        <include>**/*.md</include>
      </includes>
      <flexmark/>
    </markdown>
    <pom>
      <includes>
        <include>pom.xml</include>
      </includes>
      <sortPom>
        <encoding>UTF-8</encoding>
        <keepBlankLines>true</keepBlankLines>
        <nrOfIndentSpace>4</nrOfIndentSpace>
        <indentBlankLines>false</indentBlankLines>
        <indentSchemaLocation>true</indentSchemaLocation>
        <expandEmptyElements>false</expandEmptyElements>
        <sortProperties>true</sortProperties>
      </sortPom>
    </pom>
  </configuration>
  <executions>
    <execution>
      <id>format</id>
      <goals>
        <goal>check</goal>
        <goal>apply</goal>
      </goals>
      <phase>process-sources</phase>
    </execution>
  </executions>
</plugin>


Hiç yorum yok:

Yorum Gönder

Local Snapshot Kullanmak

Örnek Şöyle yaparız <repository> <id>snapshot-repository</id> <name>Maven2 Snapshot Repository</name> &l...