我正在使用 BOM 将依赖项从另一个项目导入到我的项目中,我需要一种方法来引用已在所述 BOM 中声明的依赖项版本。到目前为止,我已经尝试将依赖项版本列为 BOM 中的一个属性,但这种方法失败了,因为属性不会随 BOM 一起导入。
我已经看到依赖插件的 dependency:properties 在哪里目标 几乎 完全符合我的需要,但我需要的不是 Artifact 的完整路径,而是版本作为属性。有没有什么东西可以给我已解决 Artifact 的版本作为属性?
更新 - “为什么不使用父 pom?”
我经常发现自己在应用程序服务器环境中工作,其中提供的依赖项是用 BOM Artifact 指定的(因为这似乎已经成为分发相互关联的 Artifact 组的一种通用/标准方式,即 widlfly ) .因此,我想将 BOM 视为唯一的真实来源。执行类似重新分配 BOM 中已定义的依赖项版本属性的想法似乎是不正确的。
如果我要在反射(reflect)应用程序服务器环境的父 pom 中定义属性,我现在必须担心保持父 pom 属性和 BOM 属性同步——为什么那时还要有 BOM?
依赖树上的信息已经可用,只需要公开它...
最佳答案
找不到任何现有的 maven 或插件功能,所以我 fork 了旧的 dependencypath-maven-plugin 并将其更改为使用版本。现在我可以加入这样的插件了:
<build>
.
.
<plugins>
.
.
<plugin>
<groupId>io.reformanda.semper</groupId>
<artifactId>dependencyversion-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>set-all</id>
<goals>
<goal>set-version</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
并像这样访问属性:
groupId:artifactId:type[:classifier].version
即
io.undertow:undertow-core:jar.version=1.3.15.Final
查看 README有关如何使用该插件的更多信息。它可用@ Maven Central :
<dependency>
<groupId>io.reformanda.semper</groupId>
<artifactId>dependencyversion-maven-plugin</artifactId>
<version>1.0.0</version>
</dependency>
...插件一直向下...
关于java - Maven 是否有办法将依赖版本作为属性获取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37735959/