【问题标题】:Exclude *target* directory from the maven-checkstyle-plugin scan从 maven-checkstyle-plugin 扫描中排除 *target* 目录
【发布时间】:2018-05-26 04:21:24
【问题描述】:

我在 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>

【问题讨论】:

标签: java maven pom.xml maven-checkstyle-plugin


【解决方案1】:

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

<sourceDirectories>
  <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
  <sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>

现在只分析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>

【讨论】:

    【解决方案2】:
    <excludes>**/generated/**/*</excludes>
    

    这将从插件中删除生成的文件。

    【讨论】:

      猜你喜欢
      • 2019-12-02
      • 1970-01-01
      • 2019-06-07
      • 2021-03-09
      • 2022-07-28
      • 1970-01-01
      • 2018-10-19
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多