5

我有一个带有以下结构的maven的java应用程序:

parent
| - pom.xml
| - child
    | - pom.xml
| - analyzers
    | - pmdrules.xml
    | - checkstyle.xml

我已经在父 pom.xml 中配置了 PMD 和 checkstyle。对于 PMD,规则集配置如下,它适用于父模块和子模块:

<configuration>
    <rulesets>
        <ruleset>${basedir}/../analyzers/pmdrules.xml</ruleset>
    </rulesets>
</configuration>

但是,对于 checkstyle,如果我以相同的方式配置 configLocation,它会在父级或子级中失败。我必须使用自定义属性来克服这个问题。

<configuration>
    <!-- Below config with ${projectRootDir}, a custom property always pointing to parent root works fine -->
    <configLocation>${projectRootDir}/analyzers/checkstyle.xml</configLocation>
    <!-- Below configurations with ${basedir} will fail build for child -->
    <!--<configLocation>${basedir}/analyzers/checkstyle.xml</configLocation>-->
    <!-- Below configurations with ${basedir} will fail build for parent -->
    <!--<configLocation>${basedir}/../analyzers/checkstyle.xml</configLocation>-->
</configuration>

这是一个复制器示例 - https://github.com/ramtech123/pocs/blob/master/myapp-parent-module/pom.xml

我尝试在调试模式下运行 Maven 构建。从日志中,对我来说,实际的 PMD 执行似乎只针对子模块发生,因此它正在顺利进行。

有人可以帮助我了解根本原因,并改进我的配置。

提前致谢。

4

1 回答 1

3

当您创建子pom.xml项时,它会继承其父配置,但此类属性baseDir会被子项覆盖,因此在模板化插件配置时它使用自己的路径。

作为一个选项,您可以<configLocation>analyzers/checkstyle.xml</configLocation>不使用{baseDir}or离开{projectRootDir},它工作正常。

但是,正如您在父根中指定的那样,您的解决方案也很好,projectRootDir并且在那里对其进行评估,并且子 pom 不会覆盖您的自定义属性,因此它是正确的。

您的 pmd 始终有效,因为 pmd 插件仅针对子模块运行。

于 2018-05-02T12:39:07.187 回答