Sunday, October 31, 2010

Maven Multi-module Assembly Building

My first attempt at getting a multi-module maven assembly to work gave me some difficulty. I finally figured it out though and wish to share the result of my thrashing.

To cut to the chase, I found that to get the assembly to build properly and pick up all the latest dependencies you need to make sure that the assembly module is not a parent module of any of the other modules upon which the assembly depends.

The reason for this is that maven builds parent modules first before building any of the children modules. This means that if an assembly module is a parent module then it will be built before any of the submodules are built. This means that your assembly can not pick up any of the newly built modules that are below it. Either your assembly will fail (if you have never built it before) or the assembly will include old submodules from the previous build.

I found that a structure which puts the assembly module on a different branch of the multi-module tree works best. Something like the following worked for me:

   +-- /assembly
   +-- /module
     +-- /submodule1
     +-- /submodule2

1 comment:

  1. Thanks for that tip! I also found that if you attach artifacts to your sub-modules, you can add them by specifying the tag. However, they will not get included if the sub-module is type pom. I had to look through the source code to figure that out.