Maven父模块中Checkstyle和PMD配置的差异 [英] Difference with Checkstyle and PMD configuration in maven parent module

查看:303
本文介绍了Maven父模块中Checkstyle和PMD配置的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个maven具有以下结构的Java应用程序:

I have a java application with maven having below structure:

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

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

I have configured both PMD and checkstyle in parent pom.xml. For PMD the rulesets are configured as below, and it works fine both for parent and child modules:

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

但是,对于checkstyle,如果我以相同的方式配置configLocation,则它在父项或子项中均失败.我必须使用自定义属性来克服这一点.

However, for checkstyle if I configure configLocation in the same way, it fails either in the parent or the child. I have to use a custom property to overcome that.

<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执行仅在子模块上进行,因此没有任何问题.

I tried running the maven build in debug mode. From the logs, for me it seems like the actual PMD execution is happening for only child module, hence it is going through without issues.

有人可以帮助我了解根本原因并改善我的配置.

Could someone help me understand the root cause, and improve my configuration.

谢谢.

推荐答案

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

When you create child pom.xml it inherits its parent configuration, but such properties as baseDir are overrided by child, so it uses its own path when templating your plugin configuration.

作为一种选择,您可以不使用{baseDir}{projectRootDir}保留<configLocation>analyzers/checkstyle.xml</configLocation>,它可以正常工作.

As an option you can just leave <configLocation>analyzers/checkstyle.xml</configLocation> without {baseDir} or {projectRootDir}, it works fine.

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

However your solution is also good, as you specify projectRootDir in parent root, and it is evaluated there and child pom doesn't override your custom property, thus its correct.

您的pmd始终有效,因为pmd插件仅在子模块上运行.

Your pmd always works because pmd plugin only runs for child module.

这篇关于Maven父模块中Checkstyle和PMD配置的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆