简体   繁体   中英

Controlling Maven plugin inheriting per execution

I have a project which is comprised of a parent POM and a module (let's call it “lib”). In the parent POM, I define a plugin with two executions (used to be only one). One of the executions (the new one) must be inherited by the module, the other mustn't.

So the structure is currently this:

  • toplevel/pom.xml (no parent; parent POM plus <module>lib</module> )
  • toplevel/lib/pom.xml (parent: ../pom.xml )

I used to have <inherited>false</inherited> in the plugin configuration; this obviously won't work any more now.

I defined a profile build-this with which the build is invoked, and I thought to maybe just split the plugin configuration, one <plugin> block in the profile with <inherited>false</inherited> and the other in the main <build> block (outside of all profiles) without that, but it seems that <inherited>false</inherited> is applied after plugin blocks are merged, not before.

How can I control plugin inheritance by execution?


I've got an idea, which is overly complicated and will cause quite some work, but which might do:

  • move the parent POM into a second module
  • make a new top-level POM which uses <relativePath>parent/</relativePath> (instead of the implicit <relativePath>../</relativePath> ) to find its parent POM
  • add only the <modules> from the old parent, and all plugin invocations that must not be inherited, to the top-level POM and remove them from the new parent module
  • add <relativePath>../parent/</relativePath> to the lib module's POM make the it find its parent POM

So this:

  • toplevel/pom.xml (parent: parent/pom.xml ; <module>parent</module> <module>lib</module> )
  • toplevel/lib/pom.xml (parent: ../parent/pom.xml )
  • toplevel/parent/pom.xml (no parent)

Does this look sound? It's still quite somewhat backwards (especially as it will cause installation of the new top-level POM into Maven Central as well¹), so a better way to handle this is still welcome.

① I might try either this trick or perhaps better this to avoid that… given that the new top-level POM is not referenced anywhere and doesn't produce anything… oh well maybe it will… hmm… disentangling this looks like fun (which is why I'd prefer a less complex solution)

Most of the plugins have <skip> parameter. If this is the case for your plugin, you can define two properties like <skip.firstexecution> and <skip.secondexecution> and put them into the configuration of the respective execution like <skip>${skip.firstexecution}</skip> .

Then you can skip the execution in the module by setting this property to true .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM