Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

inheritance - 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 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...