tags:

views:

1385

answers:

2

Is it possible to build multiple artifacts in a single POM file? It is not about building multiple assemblies but the artifacts have different builds and dependencies but refer the same source.

For e.g. one artifact I need to build is a WAR file which excludes certain AspectJ files from the build and the other is a JAR file which needs those Aspects to be weaved during the build.

Right now, I have 2 pom.xml's which run on 2 copies of the same source to produce the desired artifacts. Can this be done in a single POM?

A: 

hmm, i think the easiest way would be a super-pom, using the syntax. Seems like it would be easier to maintain than one pom with two targets.

+5  A: 

It is generally bad practice to try to do what you're after, though it could be done with profiles and assemblies I would recommend against it.

This is how I would approach it.

Separate the code into a jar project and configure the jar project to use the aspectj compiler plugin. Make the war project have a dependency on the jar project and the jar project have a dependency on aspectjrt. The jar dependencies you want to exclude can be specified as scope "provided" so they will not be included in the build or excluded by configuring the jar dependency to exclude those transitive dependencies (see the Transitive Dependency Exclusion section of the Dependency Mechanism documentation for details.

When the war is built, any compile-scoped dependencies (and their transitive dependencies) will be bundled into the war's WEB-INF/lib directory (i.e. aspectjrt will be included as well).

If you need to build both projects at once define an aggregator pom and specify both the jar and war projects as modules.

Rich Seller