我在我的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>
在Apache Maven Checkstyle插件版本3中指定源目录的位置我们必须使用sourceDirectories参数。然后我们只能指定应用程序/库的目录和用于Checkstyle的测试源:
<sourceDirectories>
<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
<sourceDirectory>${project.build.testSourceDirectory}</sourceDirectory>
</sourceDirectories>
现在只分析src/main/java
和src/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>
<excludes>**/generated/**/*</excludes>
这将从插件中删除生成的文件。