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

发布于 2024-08-09 04:08:51 字数 443 浏览 3 评论 0原文

我正在编写一个 Maven 插件,并且对所有参数使用默认值,如下所示:

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

现在我添加一个新参数,它是一个集合。有没有一种方法可以为参数设置默认值,如下所示?

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

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

万劫不复 2024-08-16 04:08:51

据我所知,这实际上是不可能的,没有真正的方法可以为具有多个值的参数类型(如数组、集合或映射)指定默认值,位于至少不作为参数。我过去也必须这样做,并且阅读了像 array (或collecton)这样的线程作为默认值mojo 配置参数将列表配置为插件参数的默认值,我结束了在 execute() 方法中设置默认值,就像 Chris 在 他的答案(例如,参见flexmojos:wrapper 插件 来源参数 参数)。

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

月野兔 2024-08-16 04:08:51

我不认为 Set 是明确支持的,但以下方法可以工作:

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

然后您可以使用以下方式配置它:

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

顺便说一句,这是取自 具有多个值的参数类型 部分 此页面,其中还详细介绍了允许参数具有多个值的其他方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文