简体   繁体   中英

How to replace version number in Maven submodule pom.xml files?

I have a multimodule maven project, sub modules get version number from a parent project property and artifacts are being created well.

My problem is having ${global.version} variable in submodules' pom.xml in nexus repo. commons-GOLD.jar successfully take place in nexus by getting version number (GOLD) from parent project. However, it's pom.xml file in nexus point ${global.version} instead of GOLD and when I add commons-gold as dependency mvn try to pull cenatral/myProj.parent/$%7Bglobal.version%7D/myProj.parent-$%7Bglobal.version%7D.pom

MyProject parent project pom.xml

<version>${global.version}</version>
<packaging>pom</packaging>
<modules>
    <module>commons</module>
    <module>module2</module>
and so on

<properties>
    <!-- Unique entry point for version number management -->
    <global.version>GOLD</global.version>
</properties>

Commons module pom.xml

<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>com.hmg</groupId>
    <artifactId>myproj.parent</artifactId>
    <version>${global.version}</version>
</parent>

I would like to have above ${global.version} be replaced with the property coming from parent pom.xml. Even though effective pom has the right value, nexus has raw pom and that cause maven command fail while resolving dependencies.

Tried overriding it but this didn't work.

mvn '-Dglobal.version=GOLD' dependency:tree

Or is there a way to How to ignore parent pom for dependency resolution?

GOLD artifact is there.

工件创建

POM.xml contains variable, which cause dependency resolution issue.

pom.xml 内容

If I use commons as a dependency in another project with version 1.0.0 or GOLD, regardless of version it seeks for ${version} because of its pom in nexus.

XDrive:> Failed to collect dependencies at com.xyz:common:jar:1.0.0: Failed to read artifact descriptor for com.xyz:common:jar:1.0.0: Failure to find com.xyz:myProj.parent:pom:${revision} in http://10.80.100.155:8085/repository/myProj-group/ was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

I guess you want this plugin and usage, for example:

mvn versions:set -DgenerateBackupPoms=false -DnewVersion=1.2.3

this will update all versions in all modules.

The problem here is simply that the usage of flatten-maven-plugin is not done correctly.

Furthermore you can only use only the following properties in relationship with this setup:

  • ${revision}
  • ${sha1}
  • ${changelist}

Apart from that you can use the versions-maven-plugin without defining any property. Apart from that you can use the release plugin which increments the versions number and there is usually no need to define a property (only in particular cases

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM