Difference with Checkstyle and PMD configuration in maven parent module

别等时光非礼了梦想. 提交于 2019-12-10 14:01:56

问题


I have a java application with maven having below structure:

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

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>

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>

Here is a reproducer sample - https://github.com/ramtech123/pocs/blob/master/myapp-parent-module/pom.xml

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.

Thanks in advance.


回答1:


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.

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

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.

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



来源:https://stackoverflow.com/questions/50134050/difference-with-checkstyle-and-pmd-configuration-in-maven-parent-module

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!