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

五迷三道 提交于 2021-01-04 04:55:45

问题


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.

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]


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/64958428/how-to-replace-version-number-in-maven-submodule-pom-xml-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!