【问题标题】:Exclude in pmd not working排除在 pmd 中不起作用
【发布时间】:2016-09-24 16:28:51
【问题描述】:

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

mainProject>subProject>target>生成源。

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

<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 中完成。

【问题讨论】:

    标签: java maven pmd


    【解决方案1】:

    在您的子 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]

    子中的插件定义看起来像

            <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>
    

    【讨论】:

      【解决方案2】:

      您可以使用excludeRoots 参数来执行此操作。这可以从 PMD 报告和后续检查中排除源目录。 Maven subProject 的示例配置为:

      <plugin>
        <artifactId>maven-pmd-plugin</artifactId>
        <version>3.6</version>
        <configuration>
          <excludeRoots>
            <excludeRoot>target/generated-sources</excludeRoot>
          </excludeRoots>
        </configuration>
      </plugin>
      

      【讨论】:

      • 感谢您的回复,但即使这样也无济于事。我已经用我尝试过的方法更新了我的问题。
      • @Karthik 你把这个放在subProject POM 中了吗?使用mvn clean install pmd:pmd pmd:check 运行 Maven。
      • 没有。我在父 POM 中有这个。运行该命令没有帮助。
      • @Karthik 那是预期的,正如我在答案中所说,你需要在subProject 中拥有它。如果你在父项目中有这个,那么你必须有&lt;excludeRoot&gt;subProject/target/generated-sources&lt;/excludeRoot&gt;,但是父项目依赖它的模块并不是一个好主意。
      • 我什至尝试了这个选项。它没有帮助。我想在此处添加更多信息:pmd-rules.xml 位于父文件夹中并从那里引用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-14
      • 2016-07-13
      • 2021-03-08
      • 2012-02-11
      相关资源
      最近更新 更多