gpt4 book ai didi

java - Maven 从父级继承 checkstyle

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:50:59 24 4
gpt4 key购买 nike

我有一个 parent POM 带有这个 checkstyle 配置:

<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.xmlcheckstyle-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配置文件。

最佳答案

来自文档

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children. The children have every right to override pluginManagement definitions.

考虑到您继承的 POM,使用的 maven-checkstyle-plugin 将是您首先声明的(在 pluginManagement 之外)。取而代之的是,对于 继承的 pom.xml,要覆盖配置,您必须在 plugins 而不是 下指定相同的配置插件管理。尝试将 pom 的构建标记简化为 --

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!--Note - the version would be inherited-->
<configuration>
<configLocation>${project.parent.basedir}/${checkstyle.configLocation}</configLocation>
<suppressionsFile>${project.parent.basedir}/${checkstyle.suppressionsLocation}</suppressionsFile>
</configuration>
</plugin>
</plugins>
</build>

编辑:- 从评论中可以看出,OP 没有使用简单 Inheritance structure因此,在这种情况下,使用相对路径 可以解决问题。

关于java - Maven 从父级继承 checkstyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42789177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com