我在Maven构建中添加了checkstyle,但是由于某种原因,它仅检查src / main文件夹,而忽略src / test文件夹,这是我的项目结构:
Proj
- Module A
- src
- main
- java
- resources
- test
- java
- resources
- Module B
- src
- main
- java
- resources
- test
- java
- resources
pom.xml
checkstyle.xml
和我的pom.xml
<properties>
<checkstyle.version>3.0.0</checkstyle.version>
<checkstyle.config.location>checkstyle.xml</checkstyle.config.location>
<checkstyle.consoleOutput>true</checkstyle.consoleOutput>
<checkstyle.failOnViolation>true</checkstyle.failOnViolation>
<encoding>UTF-8</encoding>
</properties>
<build>
<pluginManagement>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.18</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<testSourceDirectories>src/test/java</testSourceDirectories>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
答案 0 :(得分:0)
在<plugin>
标签下设置配置,如下所示:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.27</version>
</dependency>
</dependencies>
<configuration>
<configLocation>checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>