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 well1), 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)
question from:
https://stackoverflow.com/questions/66056922/controlling-maven-plugin-inheriting-per-execution 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…