简体   繁体   English

如何为具有Maven插件的多个值的参数配置默认值

[英]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: 我正在编写一个Maven插件,我正在使用所有参数的默认值,例如:

/**
 * 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 . 所知,这实际上是不可能的,没有真正的方法来为具有多个值的参数类型 (如数组,集合或映射)指定默认值,至少不作为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). 我过去也必须这样做,并且读取了像array(或collecton)这样的线程作为mojo配置参数的 默认值或者将列表配置为插件参数的默认值 ,我最终设置了execute()默认值execute()方法,像克里斯的评论中提及了他的答案 (例如见的Flexmojos:包装插件来源参数参数)。

I don't think that Set is explicitly supported but the following will work: 我不认为Set是明确支持的,但以下内容将起作用:

/**
 * 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. 顺便说一下,这是从本页的“ 具有多个值参数类型”部分中获取的, 部分还详细说明了允许具有多个值的参数的其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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