简体   繁体   中英

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

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;

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM