2017-09-01 375 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