如何使用checkstyle排除文件

问题描述 投票:0回答:1

我试图排除 src/main 上文件的 checkstyle 我只想检查测试文件夹中的文件,这就是我添加 includeTestSourceDirectory.

的原因

我尝试过这个

<excludeFiles>src/main/**/*.java</excludeFiles>
但没有成功

这是我的 maven-checkstyle-plugin 的当前设置:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <configLocation>checkstyle.xml</configLocation>
                            <includeTestSourceDirectory>true</includeTestSourceDirectory>
                            <excludeFiles>src/main/**/*.java</excludeFiles>
                            <failOnViolation>true</failOnViolation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

正如你在下面的图片中看到的,当我运行时

mvn clean install checkstyle:check
看到,在用蓝色突出显示的文件上,文件来自 src/main ,黄色文件来自 src/test ,所以这两种类型的文件都被检查,我只想检查 src/test 中的文件

enter image description here

java maven maven-plugin checkstyle maven-checkstyle-plugin
1个回答
0
投票

就这样完成了工作

         <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <configLocation>checkstyle.xml</configLocation>
                            <sourceDirectories>
                                <sourceDirectory>${project.basedir}/src/test/java</sourceDirectory>
                            </sourceDirectories>
                            <failOnViolation>true</failOnViolation>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

感谢@Turing85

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.