How to configure defaults for a parameter with multiple values for a Maven plugin

5.8k views Asked by At

I'm writing a Maven plugin and I am using default values for all parameters such as this:

/**
 * The file with the site structure.
 * 
 * @parameter expression="${generateSite.siteFile}" default-value="${basedir}/src/oda/site.xml"
 */
private File siteFile;

Now I am adding a new parameter which is a collection. Is there a way to set default values for a parameter like the following one?

/**
 * A list of file/directory names to exclude in the processing.
 * 
 * @parameter ????
 */
private Set<String> excludes;
2

There are 2 answers

2
Pascal Thivent On BEST ANSWER

To my knowledge, this is actually not possible, there is no real way to specify default values for Parameter Types With Multiple Values (like Arrays, Collections, or Maps), at least not as parameter. I had to do this in the past too and, having read threads like array (or collecton) as a default-value of a mojo configuration parameter or configuring a list as default value for a plugin parameter, I ended up setting defaults in the execute() method, like Chris mentioned in a comment to his answer (see for example the flexmojos:wrapper plugin sources and the parameters parameter).

2
Chris On

I don't think that Set is explicitly supported but the following will work:

/**
 * A list of file/directory names to exclude in the processing.
 *
 * @parameter
 */
private String[] myFiles;

You can then configure it using:

<myFiles>
  <param>value1</param>
  <param>value2</param>
</myFiles>

BTW this was taken from the Parameter Types With Multiple Values section on this page which also details other ways to allow parameters with multiple values.