是否可以拥有具有多个 id 的 Maven 配置文件或使用不同名称重复使用配置文件?
对于我们的一个项目,我们有一个复杂的多模块设置,其中包含整个 pom 文件树。对于我们使用的插件之一,如果一个配置文件可以有多个 id,那将会非常方便。这将使我不必为多个配置文件重复相同的配置(我们大约有 7 个配置文件,但是 - 至少对于该插件 - 三个不同的配置就可以了。
所以,让我不必多次重复每个配置(并且然后保持这些副本同步)简单地为每个配置文件允许多个 id 会非常方便,
我知道这不可能直接如下面的示例所示(如果我向它提供这样一个文件,Maven 会向我大喊大叫)。有多个 id 的配置文件)但是有一些达到这种效果的技巧或解决方法?即分解配置部分并在多个配置文件中重新使用它?或者将这 7 个“全局”配置文件(即也用于其他 pom 的配置文件)“映射”到 3 个“本地”配置文件并定义仅适用于这三个的配置?
希望我能说清楚......
<profiles>
<profile>
<id>profile_1</id>
**<id>profile_2</id>**
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<... complex config here...>
</configuration>
</plugin>
</plugins>
</build>
</profile>
For one of our projects we have a complex multi-module setup with an entire tree of pom-files. For one of the plugins we use it would be very convenient if a profile could have multiple id's. This would spare me to have to repeat the same configuration for several profiles (we have about 7 profiles, but - at least for that plugin - three different configurations would do.
So, to spare me from having to repeat each config several times (and then keep those copies in sync) it would be very handy to simply allow multiple ids for each profile.
I know that this is not possible directly as sketched in the below example (Maven would yell at me if I feed it such a file with a profile that has multiple ids) but is there some trick or workaround to achieve that effect? I.e. factor out the config part and re-use it in multiple profiles? Or "map" those 7 "global" profiles (i.e. profiles also used in other pom's) to 3 "local" ones and define configs for only those 3?
Hope I could make myself clear...
<profiles>
<profile>
<id>profile_1</id>
**<id>profile_2</id>**
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<... complex config here...>
</configuration>
</plugin>
</plugins>
</build>
</profile>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不可以,您不能为一个配置文件提供多个 ID。
您可以做的是通过同一属性激活多个配置文件。
然后运行
mvn -Dprofile.both
。No, you cannot give a profile multiple IDs.
What you can do is activate multiple profiles through the same property.
Then run
mvn -Dprofile.both
.