【发布时间】:2017-08-04 23:26:51
【问题描述】:
我有一个带有这种 checkstyle 配置的 父 POM:
<properties>
<checkstyle.configLocation>src/checkstyle/checkstyle.xml</checkstyle.configLocation>
<checkstyle.suppressionsLocation>src/checkstyle/checkstyle-suppressions.xml</checkstyle.suppressionsLocation>
<maven-checkstyle-plugin.version>2.17</maven-checkstyle-plugin.version>
<properties>
<build>
<pluginManagement>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven-checkstyle-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>${checkstyle.configLocation}</configLocation>
<suppressionsLocation>${checkstyle.suppressionsLocation}</suppressionsLocation>
</configuration>
</execution>
</executions>
</plugin>
</pluginManagement>
</build>
这是继承的 POM:
<build>
<plugins>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>${project.parent.basedir}/${checkstyle.configLocation}</configLocation>
<suppressionsFile>${project.parent.basedir}/${checkstyle.suppressionsLocation}</suppressionsFile>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
我只想在继承的项目中执行 checkstyle(因为我将有多个使用父 pom 的项目)。在父项目中,不需要运行 checkstyle,但我必须在父项目上使用 checkstyle.xml 和 checkstyle-suppressions.xml 配置文件,并使用来自继承的项目。
这是mvn clean install后得到的错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (validate) on project MyProject: Failed during checkstyle execution: Unable to find suppressions file at location: src/checkstyle/checkstyle-suppressions.xml: Could not find resource 'src/checkstyle/checkstyle-suppressions.xml'. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
子项目没有找到父项目的checkstyle配置文件。
【问题讨论】:
-
日志读取 src/checkstyle/checkstyle-suppressions.xml:,而属性则不同 src/**main/resources**/checkstyle-抑制.xml。即使无法获得正确的父路径,使用属性替换的路径值也不会反映在日志中。请确认您分享的路径值和日志是否正确。
-
对不起,我复制了一个不好的属性。在我的电脑中,这些属性都可以。
-
在继承的 pom 中使用值为
${project.parent.basedir}/${checkstyle.configLocation}的属性并在配置中替换它可以解决吗? -
如果我在子 pom 中更改并添加此属性:
<checkstyle.configLocation>C:\Users\daniel\git\parent-project\src\checkstyle\checkstyle.xml</checkstyle.configLocation><checkstyle.suppressionsLocation>C:\Users\daniel\git\parent-project\src\checkstyle\checkstyle-suppressions.xml</checkstyle.suppressionsLocation>它工作正常。但这不是想法。 -
您也可以在继承的 pom 中添加类似的属性,您可以使用不同的值作为 -
${project.parent.basedir}/${checkstyle.configLocation},然后可以在配置中使用该 prperty
标签: java maven inheritance maven-plugin checkstyle