报告期间不考虑在pluginManagement中添加的依赖项 [英] Dependencies added in pluginManagement not considered during reporting

查看:93
本文介绍了报告期间不考虑在pluginManagement中添加的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置Maven Checkstyle插件以进行报告,并希望将Checkstyle的依赖项更改为7.5,而不是默认的6.11.2.

I am trying to configure the Maven Checkstyle Plugin for reporting and would like to change the dependency of Checkstyle to 7.5 instead of the default 6.11.2.

要实现这一点,请在父pom中将pluginManagement声明为具有依赖项. 在子项目中,我只是在报告标签中引用了该插件.

To achieve this I, have pluginManagement declared in parent pom with the dependency. In the child project, I am just referencing the plugin in the reporting tag.

但是,我看到默认的Checkstyle(6.11.2)正在下载到存储库中.请参见下面的父母和孩子pom.

However I see that default Checkstyle (6.11.2) is being downloaded into the repository. Please see below parent and child pom.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.app</groupId>
  <artifactId>parent_app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>parent_app</name>
  <modules>
    <module>my-app2</module>
  </modules>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-checkstyle-plugin</artifactId>
          <version>2.17</version>
          <dependencies>
            <dependency>
              <groupId>com.puppycrawl.tools</groupId>
              <artifactId>checkstyle</artifactId>
              <version>7.5</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

子pom.xml

 <?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.mycompany.app</groupId>
    <artifactId>parent_app</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <groupId>com.mycompany.app</groupId>
  <artifactId>my-app2</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>my-app2</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
   <reporting>
    <plugins>
        <plugin>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <configuration>
                <configLocation>src/main/resources/checkstyle.xml</configLocation>
            </configuration>
            <reportSets>
                <reportSet>
                    <reports>
                        <report>checkstyle</report>
                    </reports>
                </reportSet>
            </reportSets>
        </plugin>
    </plugins>
</reporting>
</project>

如果这是覆盖报告插件依赖关系的正确方法,您能帮忙吗?如果是这样,为什么它不起作用?

Can you please help if this is the right way to override dependency for reporting plugin? If so why is it not working?

Maven版本:3.2.5

推荐答案

Maven网站插件似乎有一个错误(在

It looks like there is a bug here with the Maven Site Plugin (a regression introduced after MSITE-507). The dependencies explicitly added to the managed plugins configured in the build are indeed not taken into account, unless the plugin is also declared itself. That is to say, the following in the parent POM will give you the wanted behaviour (tested with Maven 3.3.9):

<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-checkstyle-plugin</artifactId>
        <version>2.17</version>
        <dependencies>
          <dependency>
            <groupId>com.puppycrawl.tools</groupId>
            <artifactId>checkstyle</artifactId>
            <version>7.5</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </pluginManagement>
  <plugins>
    <plugin>
      <artifactId>maven-checkstyle-plugin</artifactId>
    </plugin>
  </plugins>
</build>

在本地存储库中安装了新的父级,并启动了子级构建时(例如,使用mvn clean site),将使用预期的Checkstyle 7.5.

When that new parent is installed in the local repository, and the build on the child is launched (with mvn clean site for example), it is the expected Checkstyle 7.5 that will be used.

这篇关于报告期间不考虑在pluginManagement中添加的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆