【发布时间】:2019-05-11 15:11:29
【问题描述】:
为什么<plugin> 的<dependencies> 只能在<build> 部分中定义,而不能在pom 的<reporting> 部分中定义?
- 为什么 maven
pom.xml语法在<reporting>中不允许<dependencies>?- 如果用户只想为
<reporting>配置插件并设置依赖版本怎么办?
- 如果用户只想为
-
<build>依赖信息如何/为什么被<reporting>部分中的插件使用?
我拥有找到的文档,我在下面解释了为什么它没有回答这个问题(文档中的混乱实际上是我在这里问这个问题的原因!)。
根据我的阅读、观察和尝试,这是我目前的理解:
脚本
<build>部分中的插件可以覆盖默认依赖信息,这将影响<reporting>部分中插件的依赖关系。因此,插件依赖信息不需要在<reporting>部分,只需在<build>部分。
这是正确的吗?文档中是否有说明这一点的地方?为了正确理解 <dependencies> 的 <build> 和 <reporting> 插件配置之间的关系,我遗漏了哪些细节?
来自 Maven 文档
它在 Maven 文档Using the Reporting vs the Build Tag 上说:
使用
<reporting>标签 VS<build>标签
在 pom 中的<reporting>或<build>元素中配置报告插件没有相同的行为!
mvn site
它仅使用在<reporting>元素中指定的每个报告插件的<configuration>元素中定义的参数,即站点始终忽略在<build>中指定的每个插件的<configuration>元素中定义的参数。
文档明确指出<configuration> 不在<build> 和<reporting> 之间共享,但是
我的问题是关于 <dependencies> 以及它们如何/为什么只在 <build> 中声明,而不是在 <reporting> 中声明。
似乎<build> do 中指定的依赖项会延续到<reporting> 插件。但这是我想要确认/解释的一点。
小例子
我遇到了这个问题upgrading the dependencies for the CheckStyle plugin at runtime 与mvn site 一起使用,所以这个最小的示例 POM 以 Checkstyle 插件为例演示了这个问题。
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mylib</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.15</version> <!-- Update from default 6.18 to 8.15 -->
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<!-- Uncommenting will cause syntax error, Dependencies can't be declared in reporting -->
<!-- <dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.15</version>
</dependency>
</dependencies> -->
</plugin>
</plugins>
</reporting>
</project>
【问题讨论】:
标签: maven checkstyle maven-checkstyle-plugin