我无法对 PMD 进行排除。我需要排除位于以下目录结构中的 generated-sources 文件夹:
mainProject>subProject>target>generated-sources.
我已经尝试了如下所示的规则集:
<exclude-pattern>.*/generated-sources/*.java</exclude-pattern>
<exclude-pattern>.*/generated-sources/.*</exclude-pattern>
我还查看了他们的文档和其他堆栈溢出链接,但似乎无济于事。我尝试使用 maven-pmd-plugin 3.1 和 3.6 版本。
尝试了其他选项:
<!-- <excludeRoots>
<excludeRoot>target/generated-sources/**</excludeRoot>
</excludeRoots> -->
<!-- <excludes>
<exclude>target/generated-sources/*.*</exclude>
</excludes> -->
<!-- <excludeRoots>
<excludeRoot>target/generated-sources/**</excludeRoot>
</excludeRoots> -->
<!-- <excludes>
<exclude>${basedir}/target/generated-sources/*.java</exclude>
</excludes> -->
<!-- <excludeRoots>
<excludeRoot>${basedir}/target/generated-sources/**</excludeRoot>
</excludeRoots> -->
<!-- <excludes>
<exclude>**/generated-sources/**/*.java</exclude>
</excludes> -->
<excludeRoots>
<excludeRoot>target/generated-sources</excludeRoot>
</excludeRoots>
所有这些更改都在父 POM 中完成。
最佳答案
在您的子 pom 中,excludeRoots 需要与 compileSourceRoots 中列出的完整文件夹名称相匹配,例如
[DEBUG] (f) compileSourceRoots = [project/src/main/java, project/target/generated-sources/antlr4, project/target/generated-sources/annotations]
[DEBUG] (f) excludeRoots = [project/target/generated-sources/antlr4, project/target/generated-sources/annotations]
child 中的插件定义看起来像
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<excludeRoots>
<excludeRoot>target/generated-sources/antlr4</excludeRoot>
<excludeRoot>target/generated-sources/annotations</excludeRoot>
</excludeRoots>
</configuration>
</plugin>
关于java - 在 pmd 中排除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38120060/