4

I have a plugin that takes a list inside its configuration:

<build>
  <plugins>
    <plugin>
      <groupId>com.example</grouId>
      <artifactId>fictional-plugin</artifactId>
      <configuration>
        <fictionalSet>
          <setItem>First</setItem>
          <setItem>Second</setItem>
          <setItem>Third</setItem>
        </fictionalSet>
  ...
</build>

The contents of <fictionalSet> will change based on the current profile. Right now I am duplicating the plugin definition inside a profile and that feels a bit wasteful. What I'd really like is to define a set of items as a property:

<properties>
  <fictional.set.items>
    <setItem>First</setItem>
    <setItem>Second</setItem> 
 ...
</properties>

However, if I attempt the above then I get an error from Maven:

[ERROR]     Non-parseable POM <path>/pom.xml: TEXT must be immediately followed 
by END_TAG and not START_TAG (position: START_TAG seen ...
<fictional.set.items>\r\n\t\t\t<setItem>... @37:13)  @ line 37, column 13

Is there a way to pass a list from a Maven property into a plugins configuration?

James Fassett
  • 40,306
  • 11
  • 38
  • 43

1 Answers1

0

Maven doesn't support any sort of list or way to store several properties/tags inside one tag. However, you don't need to duplicate the plugin configuration, you can just move it entirely into the profiles and not have it defined in the main pom at all (alternate: still remove it from the main pom but make an activeByDefault profile which has the default plugin configuration). As maven doesn't bother parsing inactive profiles the duplicate code shouldn't cause any performance problems.

matt5784
  • 3,065
  • 2
  • 24
  • 42
  • 1
    It's not performance but maintenance that I am worried about. I've centralized my plugin version as properties so that should help but due to the inheritance rules of profiles it can get tricky to determine what configurations apply to which profiles. It is a real shame that Maven doesn't allow lists as properties. – James Fassett Jun 04 '12 at 19:03
  • I think the implementation (maybe just the parser) assumes a known/static number of arguments for a given configuration item. There is also no list implementation defined, so when it gets to your tag which declares the list all it knows how to do is check it against the known configuration tags and spit it back at you if it doesn't match anything on the list. Some sort of extremely low level change would likely be required to get the functionality you want. – matt5784 Jun 04 '12 at 19:27
  • I don't know where the maven parsing is implemented but this is a link to the code for an XML parser if you are interested in trying to edit something: http://plexus.codehaus.org/plexus-utils/xref/org/codehaus/plexus/util/xml/pull/MXParser.html – matt5784 Jun 04 '12 at 19:27