排除 pmd 不工作

Kar*_*hik 2 java pmd maven

我无法使 PMD 的排除工作。我需要排除以下目录结构中的 generated-sources 文件夹:

主项目>子项目>目标>生成源。

我已经尝试过如下所示的规则集:

<exclude-pattern>.*/generated-sources/*.java</exclude-pattern>
<exclude-pattern>.*/generated-sources/.*</exclude-pattern>
Run Code Online (Sandbox Code Playgroud)

我还浏览了他们的文档和其他堆栈溢出链接,但似乎没有任何帮助。我尝试使用 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>
Run Code Online (Sandbox Code Playgroud)

所有这些更改都是在父 POM 中完成的。

Dam*_*ill 7

在您的子 pom 中,excludeRoots 需要与compileSourceRoots 中列出的完整文件夹名称匹配,例如

[调试] (f)compileSourceRoots = [项目/src/main/java, 项目/目标/生成源/antlr4, 项目/目标/生成源/注释]

[调试] (f) excreRoots = [项目/目标/生成源/antlr4,项目/目标/生成源/注释]

子项中的插件定义如下所示

        <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>
Run Code Online (Sandbox Code Playgroud)