从 maven-checkstyle-plugin 扫描中排除 *target* 目录

Cod*_*ven 2 java pom.xml maven maven-checkstyle-plugin

我在 pom.xml 中使用 Apache Maven Checkstyle 插件。我试图从检查式扫描中排除目标目录,但到目前为止还没有运气。这是我正在尝试的 pom 代码。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <executions>
                <execution>
                    <id>checkstyle-check</id>
                    <phase>test</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <configLocation>checkstyles.xml</configLocation>
                <failsOnError>true</failsOnError>
                <failOnViolation>true</failOnViolation>
                <consoleOutput>true</consoleOutput>
                <includes>**\/*.java,**\/*.groovy</includes>
                <excludes>**WHAT GOES HERE TO EXCLUDE THE TARGET DIRECTORY**</excludes>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

Bor*_*ris 5

在 Apache Maven Checkstyle 插件版本 3 中,要指定源目录的位置,我们必须使用sourceDirectories参数。然后我们可以仅指定用于 Checkstyle 的应用程序/库和测试源的目录:

<sourceDirectories>
  <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
  <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>
Run Code Online (Sandbox Code Playgroud)

现在仅对src/main/javasrc/test/java进行分析。

这是我的完整工作示例:

<!-- Apache Maven Checkstyle Plugin (checks Java code adheres to a coding standard) -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-checkstyle-plugin</artifactId>
  <version>${maven-checkstyle-plugin.version}</version>
  <executions>
    <execution>
      <phase>test</phase>
      <goals>
        <goal>check</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <sourceDirectories>
      <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
      <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
    </sourceDirectories>
    <!-- relates to https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml -->
    <configLocation>/src/main/resources/checkstyle.xml</configLocation>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)