1

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

1 回答 1

3

<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>
于 2019-12-19T14:29:36.420 回答