We have an application with several modules that produce deployable artifacts. We separate the "parent" hierarchy from the "module" hierarchy by having "parent poms" that only specify dependencies and "aggregator poms" that only have a list of modules. We have one main aggregator pom that lists all of our modules, including the parent poms and the "artifact" poms.
Most of the "artifact" poms produce something that we eventually want to deploy to an OSGi server (karaf). We'd like to be able to run a build that builds everything and also deploys each deployable module to Karaf. We can specify the deployment with the "maven-exec-plugin". In the parent pom for all the modules that can build a deployable artifact, we specify a profile that includes the maven-exec-plugin definition.
We run the build with "mvn clean install -Pprofilename". This comes close to working, but it complains with warnings on the "parent poms" because they don't have anything to deploy.
I haven't tried this yet, but I'm theorizing that what might work is adding an "activation" section to the profile definition in the parent pom which specifies a property like "canDeployToKaraf". I then thought that we would only define this property in the poms that produce an artifact that can deploy to Karaf.
Will the profile activation be considered for each module the aggregator pom attempts to build, or will it be activated or not for the entire build? If it's the former, then it seems possible this strategy could work. If the latter, then that won't work.
Will this work? Is there a better way to do this?
Addendum:
It was just pointed out to me that it doesn't make sense to try to manually specify a profile on the command line, and then try to "not activate" the profile for certain poms. Specifying the profile on the command line "activates" the profile.
What I really need to do is figure out how to configure the "maven-exec-plugin" in the parent pom so its behavior in child poms is appropriate. In child poms that have something to deploy to Karaf, but in child poms that don't produce a deployable artifact, it does nothing.
Does anyone see a way to do that?
I think this is probably a misuse of profiles, but I won't be pushy :)
So, rather than handling the actual execution of the plugin in the parent, I would use the "plugin management" element to manage configuration of the exec plugin from the parent levels. Then I would add the plugin delcaration to each pom that actually has something to deploy.
If you are concerned that this isn't as much resuse, because my solution creates plugin elements across all of the children that need it, consider this -- it's the config of the exec plugin that you want to "reuse". Also, I personally believe it's much more readable; my litmus test for pom readability is that you can read a pom and know what it does at build time -- not so easy if its inheriting it's plugin execution.