Java 如何在全局maven父项目及其用户之间共享checkstyle XML配置/configLocation文件?
我正在开发一个Maven父项目(不是聚合器!),它包含Maven插件和其他东西,我在几乎每个项目中都会重复这些东西,我希望通过Java 如何在全局maven父项目及其用户之间共享checkstyle XML配置/configLocation文件?,java,maven,checkstyle,Java,Maven,Checkstyle,我正在开发一个Maven父项目(不是聚合器!),它包含Maven插件和其他东西,我在几乎每个项目中都会重复这些东西,我希望通过 <parent> <groupId>richtercloud</groupId> <artifactId>maven-parent</artifactId> <version>1</version> <relativePath></rel
<parent>
<groupId>richtercloud</groupId>
<artifactId>maven-parent</artifactId>
<version>1</version>
<relativePath></relativePath>
</parent>
因此,maven-checkstyle-plugin
用于包含上述parent
指令的所有项目
问题是
- 要么将上面的
部分放入父级中的插件
(没有报告
,因为这是无效的),然后忽略执行
,从而使用默认XML配置
- 或者将
部分放入父POM中的plugin
,则父项目不会编译,因为它没有在类路径(afaik)中搜索build
中指定的文件,因此由于configLocation
.Prepending未能执行目标org.apache.maven而失败(检查样式)在project maven父项上:在检查样式执行期间失败:在以下位置找不到配置文件:check_style.xml:找不到资源“check_style.xml”。->[帮助1]
有助于编译父项目,但会导致所有其他项目失败,因为它们将src/main/resources
解析为configLocation
哪一个是正确的。一个bugsrc/main/resources/src/main/resources/check_style.xml
relativePath
我使用的是Maven 3.3.9。它看起来确实像类路径中的
configLocation
。它无法构建父级,因为在构建父级时,它没有父级(因为父级声明的插件
不在
中,所以没有理由不使用checktyle)。更好的解决方案(IMO)在父级的类路径中重构check_style.xml
,或者将其重构到父级插件声明所依赖的共享库中。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>check_style</id>
<goals>
<goal>check</goal>
</goals>
<phase>validate</phase>
<configuration>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</execution>
</executions>
<configuration>
<configLocation>check_style.xml</configLocation>
</configuration>
</plugin>