2017-09-01 371 views
1

我有一个父母和孩子pom。父母定义了一些配置文件:子模块不继承从父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帮助:有效-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> 

所以我想只有性能似乎在某种程度上继承。

回答

2

正如您已经发现的那样,具有相同<id>的两个配置文件在POM继承期间未合并。什么可以作为一种解决方法做,然而,就是有型材不同<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运行现在构建激活这两个配置文件,它们共同具有所需的效果。

+0

我喜欢你的解决方案。我还注意到属性是从父pom继承的,也就是说,如果我在父级配置文件下定义一个属性,那么在调用子级时,该属性也会作为“全局”属性继承。只要看看我的Edit2。 – jlanza