首页 > 解决方案 > 在运行时更改工件版本

问题描述

我有一个 Maven 项目,它具有通过属性版本化的特定依赖项,即:

<properties>
  <version.example-artifact>1.0.0</version.example-artifact>
</properties>

<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>example-artifact</artifactId>
    <version>${version.example-artifact}</version>
  </dependency>
</dependencies>

我有这个工件的多个次要版本:

1.0.0
1.1.0

它们与 API 兼容,因此其余代码可以针对其中一个进行编译,并且无需针对另一个重新编译即可运行。

从命令行,我可以这样做:

mvn exec:java -Dversion.example-artifact=1.1.0 ...

在运行项目时更改工件版本。

在 Eclipse 中是否仅在调试/运行配置中可能出现类似的情况?具体来说,我想避免改变 pom. 我试过添加:

-Dversion.example-artifact=1.1.0

到 VM 参数,但“显示命令行”表示它仍在使用 pom.xml 中定义的工件版本(即 1.0.0)。

标签: javaeclipsemaven

解决方案


推荐阅读