2

My Maven projects are multi-module and in general the version numbers are not synced. For instance, I can have a master POM versioned as 1.2.3-SNAPSHOT and a sub-module versioned 3.4.5-SNAPSHOT (the main reason for not keeping them synced is that often a module is moved from a project to another and it has to keep its version).

Now I want to put the main project version in a resource of the module containing the main (or the webapp, etc...), which of course is a sub-module. This means that I need to access the master pom version from a sub-module.

Also be aware that my projects have got 3 or 4 levels; thus the master pom is the grandfather of the submodule, not just the parent.

In spite of having some experience with Maven including advanced stuff, so far I've been unable to solve this problem.

Thanks.

Fabrizio Giudici
  • 532
  • 3
  • 15
  • The too-obvious answer is to have the grand-master POM put the grand-master version in a property that's read by the sub-sub-module. What am I missing? – Ed Staub Aug 04 '11 at 20:41
  • ... the fact that sub-modules inherit from the grand-master. They inherit the definition of the property, rather than the value, thus they re-evaluate ${project.version} locally with their own version. – Fabrizio Giudici Aug 04 '11 at 21:09
  • Ah, maybe this works then. What I was trying to suggest was to define a property, say "grand-master.version", with the _literal_ version, _redundantly_, in the grandmaster. There's no local collision. – Ed Staub Aug 04 '11 at 23:43
  • Yes, but redundant stuff is not good... you'd always forget to update it after a release (and can't be automatically switched from -SNAPSHOT to release). – Fabrizio Giudici Aug 11 '11 at 21:21

1 Answers1

4

It should work with ${project.parent.version}.

Michael-O
  • 18,123
  • 6
  • 55
  • 121
  • 2
    Your straight suggestion wouldn't work for me, as I have three and four levels in children POMs. But you made me re-read the manual and actually `${project.parent}` refers to the whole bag of properties of the parent, including its parent. In other words, `${project.parent.parent.version}` works for three levels. I'd prefer something that works independently of the number of levels, but this approach is good for now. Probably using the Groovy Maven plugin or a similar one it is possible to write a small script that navigates through Maven properties up to the root module. – Fabrizio Giudici Aug 11 '11 at 21:23