I have a multi-module (aggregator) Maven project that also inherits properties from the parent pom. So in my parent pom.xml I have this:
<groupId>com.something.project</groupId>
<artifactId>MyProject</artifactId>
<packaging>pom</packaging>
<version>1.0.123</version>
<modules>
<module>ModuleA</module>
<module>ModuleB</module>
<module>ModuleC</module>
</modules>
I would like to have all the child modules inherit the parent version number 1.0.123
, but the child pom.xml
requires me to go ahead and hardcode the version number of the parent anyway (ModuleA pom.xml example):
<artifactId>ModuleA</artifactId>
<name>Some Amazing Thing</name>
<parent>
<relativePath>../</relativePath>
<artifactId>MyProject</artifactId>
<version>1.0.123</version>
<groupId>com.something.project</groupId>
</parent>
How can I just put the version number in the parent pom, and have the modules inherit it without having to update it in multiple places? So far I've tried ${project.version} and ${project.parent.version} and Maven seems very unhappy with that. Nor can I remove the version reference entirely.
Does anyone have a good answer for this?
In general, if you are using maven to manage the versions, it isn't a problem to put the parent version in the sub-module pom. when you run the maven release plugin, it will update all the versions in all the sub-modules for you.
UPDATE:
if you want to manage versions on your own, then you will probably be in for a bit of pain. i'm pretty sure you will have to specify the version number in each pom at least once. you can probably simplify things for yourself by writing a few scripts which do the recursive search and replace for you (instead of doing it manually).
As a bit of side context: maven is built with a "best(maven) way of doing things" mentality. if you follow that way, things generally tend to be really simple and work really well. doing things differently is often possible, but the further you get from the "best way", the more painful (or impossible) things will be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With