Update parent version in a maven project's module

17,034

versions:update-parent

If you open a terminal at the root of your project X, you can use versions:update-parent to update its parent version to the latest:

$ mvn versions:update-parent -DallowSnapshots=true

You can execute this command from TeamCity and then commit the changes to the pom. This can certainly be triggered when Y is built, you could even provide the version (it must be a list or a range):

$ mvn versions:update-parent -DparentVersion=[1.0.0,1.0.1]    //or [1.0.0,1.5.0)

Documentation

See versions-maven-plugin's documentation, especially:

  • versions:update-parent

updates the parent section of a project so that it references the newest available version. For example, if you use a corporate root POM, this goal can be helpful if you need to ensure you are using the latest version of the corporate root POM.

  • versions:set

can be used to set the project version from the command line.

  • versions:commit

removes the pom.xml.versionsBackup

  • versions:update-child-modules

updates the parent section of the child modules of a project so the version matches the version of the current project. For example, if you have an aggregator pom that is also the parent for the projects that it aggregates and the children and parent versions get out of sync, this mojo can help fix the versions of the child modules. (Note you may need to invoke Maven with the -N option in order to run this goal if your project is broken so badly that it cannot build because of the version mis-match).

Share:
17,034
Sandy
Author by

Sandy

Updated on June 12, 2022

Comments

  • Sandy
    Sandy over 1 year

    I've a strange scenario where I have a project "Y" and it has a module "X" and some other modules as well.

    X is part of a project Y however it is not linked as a module of that project. Because of that, each time a newer version of Y is released someone needs to manually update the parent version in X.

    I need to update the Y project in such a way that: a)each time the Y project is released, the parent project version in X should be automatically updated by TeamCity (in a similar way as for other modules)

    b)X must not be a part of Y distribution

    c)Once deployed in TeamCity, it should not run tests from X (they should be run with Integration tests and Release builds)

  • Sandy
    Sandy about 7 years
    Thanks Alex for the reply.As I'm quite new to Maven and want to embed this within pom. xml. I wanted to know whether there is any pom.xml equivalent to the command line argument "mvn versions:update-parent -DallowSnapshots=true"? And how can I refer the updated parent version inside the parent tag?
  • alexbt
    alexbt about 7 years
    I'm not sure what you mean. This is the maven way do to it, you need to execute this maven command to update the pom automatically
  • Sandy
    Sandy about 7 years
    Okay.....Just wanted to tell that X is a part of the Project Y but not added as a module to the project Y.In that case, how would I verify whether the X module is taking the updated version of Y? Also, I've seen that executing the command only take the most updated version. What if I want my parent to point to an older version?
  • alexbt
    alexbt about 7 years
    Then, this "mvn versions:update-parent -DparentVersion=[1.0.0,1.0.1]" should allow you to set a range of version to upgrade to
  • Sandy
    Sandy about 7 years
    How do I test the scenario that whether the X module is taking the updated version of Y as I couldn't see the module X getting created in the M2 repo?
  • alexbt
    alexbt about 7 years
    update Y, commit it, release Y. Go to X, type "versions:update-parent", it's parent gets updated, commit the pom, release X. These steps can all be done from TeamCity too.
  • Sandy
    Sandy about 7 years
    Hi Alex, thanks.The solution works perfectly if I run the "mvn versions:update-parent" However, instead of using the command line option,if I use the "version plugin" in the pom.xml of the "X" module and try to build it, then it doesn't take the updated version of Parent. I guess it'll be better if you can give me a pom entry which will do the same thing as "version:update:parent"
  • James Selvakumar
    James Selvakumar about 7 years
    Can this command be reliably used to update a project version back to SNAPSHOT after releasing a milestone?
  • S.Yavari
    S.Yavari over 4 years
    Is there any way to update the parent version to a specific version? not a range!