简体   繁体   中英

Maven: versions:update-parent followed by install installs old version

I have the two following maven projects

pom.xml (parent)

--

pom.xml (aggregate, extends parent)
|
|--pom.xml (module, extends aggregate)

Only place where the artifact version is defined is the parent. Other projects or their modules inherits the version either directly or indirectly from the parent. I want to automatically match the aggregate version and it's modules versions to parent.

After I upgraded parent version and mvn install it, I'm trying to use versions-maven-plugin to upgrade the aggregate project and it's modules to to match the new parent with following command:

mvn versions:update-parent versions:update-child-modules clean install

The aggregate parent and modules parent are upgraded correctly, however install goal still installs the version before the changes made by version-maven-plugin . If I want to install the upgraded version, I have to call mvn clean install separately after the versions plugin. Why doesn't install pick those changes made by versions plugin in the same command? I also tried to include versions:commit with no effect. Here is the build log to show what is happening.

tutoivon@IT-L-R90HKRNH MINGW64 ~/Desktop/mavenversiontest/aggregate (master)
$ mvn versions:update-parent versions:update-child-modules clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] aggregate
[INFO] module
[INFO] submodule
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aggregate 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.4:update-parent (default-cli) @ aggregate ---
[INFO] Updating parent from 1.0.0 to 2.0.0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.4:update-parent (default-cli) @ module ---
[INFO] Project's parent is part of the reactor
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building submodule 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.4:update-parent (default-cli) @ submodule ---
[INFO] Project's parent is part of the reactor
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aggregate 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.4:update-child-modules (default-cli) @ aggregate ---
[INFO] Module: module
[INFO]     parent was fi.tuomas.testi:aggregate:1.0.0
[INFO]     updated to fi.tuomas.testi:aggregate:2.0.0
[INFO] Module: module/submodule
[INFO]     parent was fi.tuomas.testi:module:1.0.0
[INFO]     updated to fi.tuomas.testi:module:2.0.0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aggregate 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ aggregate ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ aggregate ---
[INFO] Installing C:\Users\tutoivon\Desktop\mavenversiontest\aggregate\pom.xml to C:\Users\tutoivon\.m2\repository\fi\tuomas\testi\aggregate\1.0.0\aggregate-1.0.0.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ module ---
[INFO] Installing C:\Users\tutoivon\Desktop\mavenversiontest\aggregate\module\pom.xml to C:\Users\tutoivon\.m2\repository\fi\tuomas\testi\module\1.0.0\module-1.0.0.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building submodule 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ submodule ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ submodule ---
[INFO] Installing C:\Users\tutoivon\Desktop\mavenversiontest\aggregate\module\submodule\pom.xml to C:\Users\tutoivon\.m2\repository\fi\tuomas\testi\submodule\1.0.0\submodule-1.0.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] aggregate .......................................... SUCCESS [  0.125 s]
[INFO] module ............................................. SUCCESS [  0.010 s]
[INFO] submodule .......................................... SUCCESS [  0.011 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.626 s
[INFO] Finished at: 2017-09-05T11:03:49+03:00
[INFO] Final Memory: 15M/303M
[INFO] ------------------------------------------------------------------------

tutoivon@IT-L-R90HKRNH MINGW64 ~/Desktop/mavenversiontest/aggregate (master)
$ mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] aggregate
[INFO] module
[INFO] submodule
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building aggregate 2.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ aggregate ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ aggregate ---
[INFO] Installing C:\Users\tutoivon\Desktop\mavenversiontest\aggregate\pom.xml to C:\Users\tutoivon\.m2\repository\fi\tuomas\testi\aggregate\2.0.0\aggregate-2.0.0.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building module 2.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ module ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ module ---
[INFO] Installing C:\Users\tutoivon\Desktop\mavenversiontest\aggregate\module\pom.xml to C:\Users\tutoivon\.m2\repository\fi\tuomas\testi\module\2.0.0\module-2.0.0.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building submodule 2.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ submodule ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ submodule ---
[INFO] Installing C:\Users\tutoivon\Desktop\mavenversiontest\aggregate\module\submodule\pom.xml to C:\Users\tutoivon\.m2\repository\fi\tuomas\testi\submodule\2.0.0\submodule-2.0.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] aggregate .......................................... SUCCESS [  0.333 s]
[INFO] module ............................................. SUCCESS [  0.012 s]
[INFO] submodule .......................................... SUCCESS [  0.012 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.448 s
[INFO] Finished at: 2017-09-05T11:04:10+03:00
[INFO] Final Memory: 7M/240M
[INFO] ------------------------------------------------------------------------

Maven runs the versions plugin after it has resolved all dependency versions, so there's no way around invoking it twice. Once for updating the versions, and then to build the project.

The maven execution stages are very well explained in this SO answer . See particularly step 7.

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