1

I often stumble over the documentation of typed values for Maven plugin parameter. Take for example excludeRoots of the maven-pmd-plugin. It is a java.io.File[]. This could mean that it accepts

<excludeRoots>root1,root2</excludeRoots>

or

<excludeRoots>
    <excludeRoot>root1</excludeRoot/>
    <excludeRoot>root2</excludeRoot/>
</excludeRoots>

or maybe even

<excludeRoots>
    <excludeRoot path="root1"/>
    <excludeRoot path="root2"/>
</excludeRoots>

Is there a specification how non-typed character input in XML is interpreted as Java types for the plugins. Or is this up to the plugin? I'm asking about the general behaviour, not about the plugin in the example, I don't care how it works in this question.

What would be the difference to a java.util.List parameter in this example?

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • This is probably off-topic for the SO question: If the latter is the case, do you have any example of a plugin documenting it in a way that allows to use typed parameters without having to ask a search engine or SO how to use it? – Kalle Richter Jul 14 '21 at 16:08
  • I would guess the second solution, but I am not sure. – J Fabian Meier Jul 14 '21 at 16:25

1 Answers1

0

See Parameter Types With Multiple Values:

Listed below are the various types of composite objects which can be used as parameters in your mojos, along with any rules on how the values in the POM are interpreted. In general, the class of the object created to hold the parameter value (as well as the class for each element within the parameter value) is determined as follows (the first step which yields a valid class is used):

    ...

  1. For arrays, use the component type of the array (for example, use String for a String[] parameter); [...]

Once the type for the element is defined, the text in the XML file is converted to the appropriate type of object

For arrays (and collections) the declaration in the POM is:

    <container>
      <item>value1</item>
      <item>value2</item>
    </container>

On the command line it's:

... -Dcontainer=value1,value2 ...

See also Configuring Parameters, Mapping Simple Objects:

Mapping simple types, like Boolean or Integer, is very simple. The <configuration> element might look like the following:

<configuration>
  ...
  <myFile>c:\temp</myFile>

See also my answer to Any way to specify a FileSet as command line parameter?.

And there's the Maven PMD Plugin / Usage page which shows a declaration:

          ...
          <excludeRoots>
            <excludeRoot>target/generated-sources/stubs</excludeRoot>
          </excludeRoots>
          ...

Unfortunately the source on GitHub that's linked on the PMD plugin's SCM page is not the code the pmd:pmd page has been created from. There AbstractPmdViolationCheckMojo.java has only 7 @Parameters and PmdViolationCheckMojo.java has only 2 @Parameters. excludeRoots is none of them.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107