为什么 Maven 使用提供的构建插件的 pom.xml?
Why does Maven use a pom.xml of a provided build plugin?
我们确实有一个像
这样的简单的 maven pom
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xy.project.z</groupId>
<artifactId>client</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.xy.maven</groupId>
<artifactId>own-maven-plugin</artifactId>
<version>1.19.0</version>
<executions>...</executions>
</plugin>
</plugins>
</build>
</project>
你可能猜到own-maven-plugin
是我们自己在另一个项目中创建的独立版本的maven插件。到目前为止没问题。但是无处不在(至少对我而言)提供的 pom 不再 运行 了。它停止并显示以下消息:
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find org.xy.projcect:a:bundle:1.0.7-SNAPSHOT in http://repo.local:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of internal-repository has elapsed or updates are forced
发生了什么。我们已经创建了一个新版本 own-maven-plugin
这个插件总是一个包含所有必要依赖项的 fat-jar。现在我们所做的只是添加了另一个依赖项。
所以有两件事我不明白。
为什么 Maven 会尝试解析已创建的 jar 的所有依赖项,这些依赖项在 build-plugins
.
中使用
为什么我删除后问题解决了.m2/org/xy/maven/own-maven-plugin/own-maven-plugin-1.19.0.pom
这是可重现的,添加删除的 pom 构建失败。我没有在 Maven 插件 description site.
上找到任何关于我的问题的迹象
所以如果有人有解释。请告诉我。
更新一:
更新了错误消息
Maven 插件通常不构造为 fat jar。他们自己解决依赖关系。
如果你有一个 fat jar 在它的 pom 中包含依赖项,那么依赖项也可能被解析,所以你有两次 类:一次在 fat jar 中,一次在依赖项中。
我不能说这是否解释了你所有的错误,但我想如果你首先避免使用胖罐,事情会更容易。
好的,找到问题的原因了。
新的依赖项本身包含一个依赖项类型为 bundle 的依赖项。
<dependency>
<groupId>org.xy.maven</groupId>
<artifactId>own-maven-plugin-dep</artifactId>
<version>1.2.0</version>
<type>bundle</bundle>
</dependency>
删除此类型后,它又像魅力一样工作了。
我不知道为什么首先添加了<type>bundle</type>
。但我没有看到删除它有任何缺点。
阅读 this 关于捆绑包类型的内容对理解为什么删除解决了我的问题没有多大帮助。
此答案不包含问题的所有答案。如果有人提供更好的答案,我很乐意更改已接受的答案。
我们确实有一个像
这样的简单的 maven pom<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xy.project.z</groupId>
<artifactId>client</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.xy.maven</groupId>
<artifactId>own-maven-plugin</artifactId>
<version>1.19.0</version>
<executions>...</executions>
</plugin>
</plugins>
</build>
</project>
你可能猜到own-maven-plugin
是我们自己在另一个项目中创建的独立版本的maven插件。到目前为止没问题。但是无处不在(至少对我而言)提供的 pom 不再 运行 了。它停止并显示以下消息:
Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Failure to find org.xy.projcect:a:bundle:1.0.7-SNAPSHOT in http://repo.local:8081/repository/maven-public/ was cached in the local repository, resolution will not be reattempted until the update interval of internal-repository has elapsed or updates are forced
发生了什么。我们已经创建了一个新版本 own-maven-plugin
这个插件总是一个包含所有必要依赖项的 fat-jar。现在我们所做的只是添加了另一个依赖项。
所以有两件事我不明白。
为什么 Maven 会尝试解析已创建的 jar 的所有依赖项,这些依赖项在
build-plugins
. 中使用
为什么我删除后问题解决了
.m2/org/xy/maven/own-maven-plugin/own-maven-plugin-1.19.0.pom
这是可重现的,添加删除的 pom 构建失败。我没有在 Maven 插件 description site.
上找到任何关于我的问题的迹象所以如果有人有解释。请告诉我。
更新一: 更新了错误消息
Maven 插件通常不构造为 fat jar。他们自己解决依赖关系。
如果你有一个 fat jar 在它的 pom 中包含依赖项,那么依赖项也可能被解析,所以你有两次 类:一次在 fat jar 中,一次在依赖项中。
我不能说这是否解释了你所有的错误,但我想如果你首先避免使用胖罐,事情会更容易。
好的,找到问题的原因了。
新的依赖项本身包含一个依赖项类型为 bundle 的依赖项。
<dependency>
<groupId>org.xy.maven</groupId>
<artifactId>own-maven-plugin-dep</artifactId>
<version>1.2.0</version>
<type>bundle</bundle>
</dependency>
删除此类型后,它又像魅力一样工作了。
我不知道为什么首先添加了<type>bundle</type>
。但我没有看到删除它有任何缺点。
阅读 this 关于捆绑包类型的内容对理解为什么删除解决了我的问题没有多大帮助。
此答案不包含问题的所有答案。如果有人提供更好的答案,我很乐意更改已接受的答案。