0

Maven spotless プラグインを使用して Java ファイルをフォーマットしていますが、ファイルをスキップできません。と を使用excludetoggle offましたが、どちらも機能しません。

<plugin>
  <groupId>com.diffplug.spotless</groupId>
  <artifactId>spotless-maven-plugin</artifactId>
  <version>2.6.1</version>
  <configuration>
    <formats>
      <format>
        <!-- define the files to apply to -->
        <includes>
          <include>*.java</include>
        </includes>
        <excludes>
          <exclude>api/**/RayCall.java</exclude>
          <exclude>api/**/ActorCall.java</exclude>
          <exclude>runtime/*/generated/**/*.*</exclude>
        </excludes>
        <!-- define the steps to apply to those files -->
        <trimTrailingWhitespace/>
        <endWithNewline/>
        <indent>
          <tabs>true</tabs>
          <spacesPerTab>2</spacesPerTab>
        </indent>
      </format>
    </formats>
    <!-- define a language-specific format -->
    <java>
      <toggleOffOn>
        <off>// Generated by `RayCallGenerator.java`. DO NOT EDIT.</off>
      </toggleOffOn>
      <googleJavaFormat>
        <version>1.7</version>
        <style>GOOGLE</style>
      </googleJavaFormat>
    </java>
  </configuration>
</plugin>
4

1 に答える 1

2

pom.xmlスニペットによると、 2 つの異なるチェックが構成されました。

  1. 汎用フォーマット
<formats>
    <format>
        <!-- define the files to apply to -->
        <includes>
            <include>*.java</include>
        </includes>
        <excludes>
              <exclude>api/**/RayCall.java</exclude>
              <exclude>api/**/ActorCall.java</exclude>
              <exclude>runtime/*/generated/**/*.*</exclude>
        </excludes>
        <!-- define the steps to apply to those files -->
        <trimTrailingWhitespace/>
        <endWithNewline/>
        <indent>
              <tabs>true</tabs>
              <spacesPerTab>2</spacesPerTab>
        </indent>
    </format>
</formats>

このセクションでは、適切に構成されたパターンを含める/除外し、正常に動作します 2. Java 形式

<java>
    <toggleOffOn>
        <off>// Generated by `RayCallGenerator.java`. DO NOT EDIT.</off>
    </toggleOffOn>
    <googleJavaFormat>
        <version>1.7</version>
        <style>GOOGLE</style>
    </googleJavaFormat>
</java>

この場合、包含/除外パターンが構成されていないため、デフォルトが使用されます。

// for default includes
ImmutableSet.of("src/main/java/**/*.java", "src/test/java/**/*.java");

// for default excludes
Collections.emptySet();

これで、Java フォーマッターがすべての Java ファイルを分析することを簡単に理解できるようになりました。幸いなことに、<java>フォーマッターもサポート<includes>して<excludes>いるため、これは機能します。

<java>
    <toggleOffOn>
        <off>// Generated by `RayCallGenerator.java`. DO NOT EDIT.</off>
    </toggleOffOn>
    <includes>
        <include>**/*.java</include>
    </includes>
    <excludes>
        <exclude>**/api/**/RayCall.java</exclude>
        <exclude>**/api/**/ActorCall.java</exclude>
        <exclude>**/runtime/*/generated/**/*.*</exclude>
    </excludes>
    <googleJavaFormat>
        <version>1.7</version>
        <style>GOOGLE</style>
    </googleJavaFormat>
</java>

于 2020-12-26T11:53:58.377 に答える