为什么Maven插件依赖项只能在<;中指定;构建>;而不是<;报告>;?
为什么为什么Maven插件依赖项只能在<;中指定;构建>;而不是<;报告>;?,maven,checkstyle,maven-checkstyle-plugin,Maven,Checkstyle,Maven Checkstyle Plugin,为什么的只能在部分中定义,而不能在pom的部分中定义 为什么mavenpom.xml语法不允许中的? 如果用户只想为配置插件并设置依赖版本,该怎么办 部分中的插件如何/为什么使用依赖信息 在我找到的文档中,我在下面解释了为什么它没有回答这个问题(文档中的混乱实际上就是我在这里问这个问题的原因!) 根据我的阅读、观察和尝试,以下是我目前的理解: 脚本的部分中的插件可以覆盖默认依赖项信息,这将影响部分中插件的依赖项。因此,插件依赖项信息不需要在部分中,只需要在部分中 这是正确的吗?文件中是否
的
只能在
部分中定义,而不能在pom的
部分中定义
- 为什么maven
pom.xml
语法不允许
中的
?
- 如果用户只想为
配置插件并设置依赖版本,该怎么办
部分中的插件如何/为什么使用依赖信息
在我找到的文档中,我在下面解释了为什么它没有回答这个问题(文档中的混乱实际上就是我在这里问这个问题的原因!)
根据我的阅读、观察和尝试,以下是我目前的理解:
脚本的
部分中的插件可以覆盖默认依赖项信息,这将影响
部分中插件的依赖项。因此,插件依赖项信息不需要在
部分中,只需要在
部分中
这是正确的吗?文件中是否有一点澄清了这一点?为了正确理解
和
插件配置之间的关系,我遗漏了哪些详细信息
来自Maven文档
它在Maven文档中写道:
使用
标签VS
标签
在pom中的
或
元素中配置报告插件不会有相同的行为
mvn站点
它仅使用
元素中指定的每个报告插件的
元素中定义的参数,即站点始终忽略
元素中定义的参数
文档明确指出,
和
之间不共享
,但是
我的问题是关于
以及如何/为什么它们只在
中声明,而从不在
中声明
似乎
中指定的依赖项确实会遗留到
插件中。但这是我想确认/解释的一点
最小示例
我在使用mvn站点时遇到了这个问题,所以这个最小的示例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>
4.0.0
com.example
迈里布
1
org.apache.maven.plugins
maven checkstyle插件
3.0.0
com.puppycrawl.tools
代码检查
8.15
org.apache.maven.plugins
maven checkstyle插件
3.0.0
我想说,这里的情况并不是那么简单-因为
在
部分是可能的
我认为关键在于插件本身(因此每个插件可能不同)
但是首先,
和
之间的区别是什么:
在编译、测试期间使用-即在生成/分析/运行代码期间-如使用mvn clean install
在使用mvn站点生成文档时使用
所以问题是checkstyle插件在文档生成过程中需要依赖关系吗?我想不需要。所以checkstyle拒绝了
中的所有依赖关系
因此,为了证明报告中的依赖关系是可能的,请查看spotbugs(另一个著名的分析器):
com.github.spotbug
这包括了许多不仅适用于maven的最佳实践
<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.12.1</version>
<configuration>
<xmlOutput>true</xmlOutput>
<spotbugsXmlWithMessages>true</spotbugsXmlWithMessages>
<spotbugsXmlOutputDirectory>target/site</spotbugsXmlOutputDirectory>
<failOnError>false</failOnError>
<includeTests>true</includeTests>
<dependencies>
<dependency>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>7.4.3.sb</version>
</dependency>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>LATEST</version>
</plugin>
</dependencies>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>3.1.12.1</version>
<configuration>
<xmlOutput>true</xmlOutput>
<spotbugsXmlWithMessages>true</spotbugsXmlWithMessages>
<spotbugsXmlOutputDirectory>target/site</spotbugsXmlOutputDirectory>
<failOnError>false</failOnError>
<includeTests>true</includeTests>
<dependencies>
<dependency>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>7.4.3.sb</version>
</dependency>
<plugin>
<groupId>com.h3xstream.findsecbugs</groupId>
<artifactId>findsecbugs-plugin</artifactId>
<version>LATEST</version>
</plugin>
</dependencies>
</configuration>
</plugin>
</plugins>
</reporting>