Can I pass a list from a Maven property into a plugins configuration

匿名 (未验证) 提交于 2019-12-03 02:22:01

问题:

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> 

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> 

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 

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

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!