我可以将Maven属性中的列表传递到插件配置中吗 [英] Can I pass a list from a Maven property into a plugins configuration

查看:78
本文介绍了我可以将Maven属性中的列表传递到插件配置中吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插件,该插件在其配置中包含一个列表:

I have a plugin that takes a list inside its configuration:

<build>
  <plugins>
    <plugin>
      <groupId>com.example</grouId>
      <artifactId>fictional-plugin</artifactId>
      <configuration>
        <fictionalSet>
          <setItem>First</setItem>
          <setItem>Second</setItem>
          <setItem>Third</setItem>
        </fictionalSet>
  ...
</build>

<fictionalSet>的内容将根据当前配置文件而改变.现在,我正在配置文件中复制插件定义,这感觉有点浪费.我真正想要的是将一组项目定义为属性:

The contents of <fictionalSet> will change based on the current profile. Right now I am duplicating the plugin definition inside a profile and that feels a bit wasteful. What I'd really like is to define a set of items as a property:

<properties>
  <fictional.set.items>
    <setItem>First</setItem>
    <setItem>Second</setItem> 
 ...
</properties>

但是,如果尝试上述操作,则会收到Maven错误消息:

However, if I attempt the above then I get an error from Maven:

[ERROR]     Non-parseable POM <path>/pom.xml: TEXT must be immediately followed 
by END_TAG and not START_TAG (position: START_TAG seen ...
<fictional.set.items>\r\n\t\t\t<setItem>... @37:13)  @ line 37, column 13

是否可以将Maven属性中的列表传递到插件配置中?

Is there a way to pass a list from a Maven property into a plugins configuration?

推荐答案

Maven不支持任何种类的列表或方法来在一个标签内存储多个属性/标签.但是,您无需复制插件配置,您可以将其完全移动到配置文件中,而不必在主pom中进行定义(替代:仍然将其从主pom中删除,但是创建一个activeByDefault配置文件,该配置文件具有默认插件配置).由于maven不会麻烦解析非活动配置文件,因此重复的代码不会造成任何性能问题.

Maven doesn't support any sort of list or way to store several properties/tags inside one tag. However, you don't need to duplicate the plugin configuration, you can just move it entirely into the profiles and not have it defined in the main pom at all (alternate: still remove it from the main pom but make an activeByDefault profile which has the default plugin configuration). As maven doesn't bother parsing inactive profiles the duplicate code shouldn't cause any performance problems.

这篇关于我可以将Maven属性中的列表传递到插件配置中吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆