4

I have dozens of similar but not identical plugin execution configurations. I'd like to re-use parts of them.

The part that I'd like to re-use might look like this:

<reuseMe>
  <lotsOfXML/>
</reuseMe>

Now, some plugin configurations might not contain the above:

<configuration>
  <simpleStuff/>
</configuration>

But other plugin configurations might:

<configuration>
  <simpleStuff/>
  <complexStuff>
    <reuseMe>
      <lotsOfXML/>
    </reuseMe>
  </complexStuff>
</configuration>

Instead of copy pasting that fragment, which is always the same, I'd like some mechanism where I can declare reusable XML fragments, and then just "import" them:

<configuration>
  <simpleStuff/>
  <complexStuff>
    <reuseMe import="whatever"/>
  </complexStuff>
</configuration>

Short of XSL transforming my pom.xml files in a preprocessing step, is there any out-of-the-box way this can be done with vanilla Maven? Using <pluginManagement/> doesn't seem to work because that would define the <reuseMe/> content for all plugin executions as a default, not just for those that need this.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • Not perfect, but you could use the approach described in https://stackoverflow.com/questions/16540808/can-i-configure-multiple-plugin-executions-in-pluginmanagement-and-choose-from – sparty02 Feb 17 '21 at 14:56
  • @sparty02: Nope, I don't think that's it. That picks up complete plugin execution configurations, but I'd like to copy only XML fragments. – Lukas Eder Feb 17 '21 at 15:13
  • 1
    The general part of the configuration could/should be put into a appropriate parent between (`....`) the specialized parts should be put into the appropriate modules related to the `` and furthermore you can use things ``... see https://maven.apache.org/pom.html or you can overwrite the configuration via ``... the default is ``....a realy import is not possible... – khmarbaise Feb 17 '21 at 16:01
  • One way of composing: https://stackoverflow.com/questions/38558475/maven-import-plugins-configuration-from-one-project-to-another-using-maven-til – Sinisha Mihajlovski Feb 18 '21 at 19:21

1 Answers1

3

There is a JIRA for what you're requesting: https://issues.apache.org/jira/browse/MNG-5102

Opened almost 10 years ago, still not solved.

As far as I know, the only out-of-the-box Maven approach involves plugin executions.

Otherwise, it's roll your own.

P.S. Not a Maven committer; maybe one of them will see this and we'll both learn something today.

user944849
  • 14,524
  • 2
  • 61
  • 83