Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven - 'all' or 'parent' project for aggregation?

For educational purposes I have set up a project layout like so (flat in order to suite eclipse better):

-product
 |
 |-parent
 |-core
 |-opt
 |-all

Parent contains an aggregate project with core, opt and all. Core implements the mandatory part of the application. Opt is an optional part. All is supposed to combine core with opt, and has these two modules listed as dependencies.

I am now trying to make the following artifacts:

  1. product-core.jar
  2. product-core-src.jar
  3. product-core-with-dependencies.jar
  4. product-opt.jar
  5. product-opt-src.jar
  6. product-opt-with-dependencies.jar
  7. product-all.jar
  8. product-all-src.jar
  9. product-all-with-dependencies.jar

Most of them are fairly straightforward to produce. I do have some problem with the aggregating artifacts though. I have managed to make the product-all-src.jar with a custom assembly descriptor in the 'all' module which downloads the sources for all non-transitive deps, and this works fine. This technique also allows me to make the product-all-with-dependencies.jar.

I however recently found out that you can use the source:aggregate goal in the source plugin to aggregate sources of the entire aggregate project. This is also true for the javadoc plugin, which also aggregates through the usage of the parent project.

So I am torn between my 'all' module approach and ditching the 'all' module and just use the 'parent' module for all aggregation. It feels unclean to have some aggregate artifacts produced in 'parent', and others produced in 'all'. Is there a way of making an 'product-all' jar in the parent project, or to aggregate javadoc in the 'all' project? Or should I just keep both?

Thanks

like image 805
Alexander Torstling Avatar asked May 12 '10 17:05

Alexander Torstling


People also ask

What is Maven aggregator project?

In Maven, project aggregation is similar to project inheritance, except that the change is made in the parent pom instead of the child pom. Maven uses the term module to define a child or subproject, which is part of a larger project. An aggregate project can build all the modules together.

What is the use of parent in Maven?

A parent pom. xml file (or super POM) in Maven is used to structure the project in order to avoid redundancies and duplicate configurations by using an inheritance between different pom. xml files. If any dependency or properties are configured in both - parent and child - pom.

What is aggregator pom?

To simplify building multiple projects, you can optionally create an aggregate Maven project. This consists of a single POM file (the aggregate POM), usually in the parent directory of the individual projects. The POM file specifies which sub-projects (or modules) to build and builds them in the specified order.

Can a Maven project have multiple pom files?

Yes you can use Maven Profiles to manage this. Obviously you can tweak this approach to suit your needs however works best.


1 Answers

Flattened trees are not often used anymore. This was done several years ago to deal with how Eclipse handled projects and the lack of good Maven and Eclipse integration. If you use m2eclipse to import Maven projects into Eclipse, you won't have any problems with a maven-typical nested tree.

As far as what is a good example of how to structure a Maven build? The Maven project source itself. It has all the pieces you desire, including the final assembly that packages up the bundles.

The typical nested structure has a top down hierarchy where the parent is doing the aggregation of the modules below it, and the children are inheriting values from the parent. Although these can and sometimes are separate, this is not the norm.

like image 163
Brian Fox Avatar answered Sep 21 '22 23:09

Brian Fox