我有一个父母和孩子的pom。父级定义了一些配置文件:
<profiles>
<profile>
<id>local</id>
<properties>
<build.profile.id>local</build.profile.id>
</properties>
</profile>
</profiles>
然后,孩子们为这些配置文件定义了更多属性。
<profiles>
<profile>
<id>local</id>
<properties>
<name>serviceA</name>
</properties>
</profile>
</profiles>
如果我只调用子个人资料mvn help:effective-pom -pl child
,则父母中定义的属性不会显示。它只显示孩子一个,所以父母被遗忘了。
有什么方法可以继承父级并在子级中修改/扩展?
编辑1:可能的答案 我发现this link他们说:
不幸的是,父pom继承有一些限制。其中之一是配置文件不是继承的。
所以也许这是不可能的。你们有什么感想?这几年有变化吗?
编辑2:以某种方式继承属性
通过运行mvn help:effective-pom -Plocal我得到了
...
<properties>
<build.profile.id>local</build.profile.id>
<name>serviceA</name>
</properties>
<profiles>
<profile>
<id>local</id>
<properties>
<name>serviceA</name>
</properties>
</profile>
</profiles>
所以我觉得只有属性才能以某种方式继承。
答案 0 :(得分:3)
正如您已经发现的那样,在POM继承期间,两个具有相同<id>
的配置文件未合并。但是,您可以采取的解决方法是使两个配置文件具有不同的<id>
但具有相同的<activation>
condition:
<profiles>
<profile>
<id>local-parent</id>
<activation>
<property>
<name>local</name>
</property>
</activation>
<properties>
<build.profile.id>local</build.profile.id>
</properties>
</profile>
</profiles>
和
<profiles>
<profile>
<id>local-child</id>
<activation>
<property>
<name>local</name>
</property>
</activation>
<properties>
<name>serviceA</name>
</properties>
</profile>
</profiles>
使用-Dlocal
而不是-P local
运行构建现在会激活两个个人资料,这些资料会共同产生预期效果。