我有一个带有 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 https://github.com/ramtech123/pocs/blob/master/myapp-parent-module/pom.xml
我尝试在调试模式下运行 Maven 构建。从日志来看,对我来说,实际的 PMD 执行似乎只发生在子模块中,因此它不会出现任何问题。
有人可以帮助我了解根本原因并改进我的配置吗?
提前致谢。
当你创建孩子时pom.xml
它继承了它的父配置,但是诸如baseDir
被子进程覆盖,因此在模板化插件配置时它使用自己的路径。
作为一个选择,你可以离开<configLocation>analyzers/checkstyle.xml</configLocation>
没有{baseDir}
or {projectRootDir}
,效果很好。
但是,正如您所指定的,您的解决方案也很好projectRootDir
在父根目录中,它在那里进行评估,并且子 pom 不会覆盖您的自定义属性,因此它是正确的。
您的 pmd 始终有效,因为 pmd 插件仅针对子模块运行。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)