I have a set of projects which all need to run the same series of Maven plugin executions during their builds. I'd like to avoid re-declaring all of this configuration in every project, so I made them all inherit from a parent pom "template" project which only contains those plugin executions (8 different mojos). But I want those plugin executions to only run on the child projects and not on the parent project during Maven builds.
I've tried to accomplish this four different ways, each with a side-effect I don't like.
Declare the plugin executions in the parent pom's build/plugins
element and use properties-maven-plugin to turn on the skip
properties on other plugins in the parent project. This didn't work because one of the plugin goals (maven-dependency-plugin:build-classpath) doesn't have a skip
property.
Declare the plugin executions in the parent pom's build/pluginManagement
element. Unfortunately this requires me to redeclare each of the eight plugins in the build/plugins
element of every child project's pom like:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
...
This is too repetitive, and problematic if I ever need to change the plugins in the template pom.
Declare the plugin executions in a profile in the parent pom which is activated by the lack of a nobuild.txt
file (which does exist in the parent pom, so the plugins don't execute there):
<profiles>
<profile>
<activation>
<file>
<missing>nobuild.txt</missing>
</file>
</activation>
<build>
....
</build>
</profile>
</profiles>
This works for the most part, except that the file path in the missing
element seems to be based on the current working directory instead of the project basedir. This breaks some of the multimodule builds I'd like to be able to do. Edit: to clarify, the parent "template" project is actually itself a module in a multimodule project, and the build breaks when I try, for instance, to do a mvn install
on the root. The project structure looks like:
+ job
|- job-core
|- job-template
|- job1 inherits from job-template
|- job2 inherits from job-template
Set up a custom lifecycle and packaging. This seems to allow me to bind plugins to lifecycle phases, but not specify any configuration.
So, is there another way to specify a bunch of Maven plugin executions that can be reused across several projects (with minimal repetition in each of those projects' poms)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…