我尝试了四种不同的方法来实现这一点,但每种方法都有我不喜欢的副作用。
Declare the plugin executions in the parent pom's
build/plugins
element and use properties-maven-plugin to turn on theskip
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 askip
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 thebuild/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 amvn 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.
那么,是否有另一种方法来指定一堆Maven插件执行,可以在多个项目中重复使用(并且在这些项目的每个pom中最小化重复)?
<missing>${basedir}/nobuild.txt</missing>
呢?这可能是一个执行其他 mojos 组合的 Maven 插件的好用例。但我不相信这样的插件已经存在。 - SpaceTrucker