3

In the Sonatype Maven Guide the example multi-module project must define the version of the project in the parent pom.xml and in all the child pom.xmls (to refer to the version of the parent).

Is there a way to define the version in a single location? It seems like an awfully lot of changes need to be made to bump the version.

fommil
  • 5,757
  • 8
  • 41
  • 81

1 Answers1

2

In my opinion the correct way to organize a multi-module Maven project is to have one project to keep track of artifact versions by means of its dependencyManagement section, which is the parent of all other projects; and an aggregator project which contains all the other projects as modules, parent included.

This allows you to centralize version handling for dependencies both between your projects and towards external libraries. You still have to explicitly keep track of the correspondence between each project's version in its pom and in the parent project, as well as the correspondence between the parent's version in its pom and in all its descendents.

I agree that it's a lot of work, and it's very easy to make mistakes: consider automating it with custom plugins and/or scripts. The Maven Release plugin could be of help on this problem.

Nicola Musatti
  • 17,834
  • 2
  • 46
  • 55
  • 1
    what is the advantage of having a parent plus aggregator over having just a parent that does the aggregation? – fommil Jun 25 '13 at 22:22
  • It is a better separation of concerns. Having dependency management separate from aggregation makes it easier to reuse specific projects in different contexts, should the need arise. Moreover, depending on which version control tool you use, you might be able to have different aggregators that combine overlapping subsets of sub-projects, for instance to turn a single product in a product family. – Nicola Musatti Jun 25 '13 at 22:32
  • I'm accepting this answer as essentially "No, it is not possible to... and here is some extra relevant information" – fommil Jun 30 '13 at 12:57