One profile properties are overriding with another profile properties in maven?

淺唱寂寞╮ 提交于 2019-12-13 00:45:58

问题


I have a problem with maven profiles. Coming to the details, I have two profiles like profile1 and profile2. I have declared few properties for both the profiles along with the modules which needs to be updated by each profile individually. Let see the below configuration,

<profiles>
    <profile>
         <id>profile1</id>
         <properties>
              <owner>ABC</owner>
         </properties>
         <modules>
            <module>module1</module>
            <module>module2</module>
         </modules>
     <profile>
     <profile>
         <id>profile2</id>
         <properties>
              <owner>XYZ</owner>
         </properties>
         <modules>
            <module>module3</module>
            <module>module4</module>
         </modules>
     <profile>
</profiles>

Coming to the point, profile1 property ABC has to update in module1 and module2 and profile2 property XYZ has to update in module3 and module4. while building the application I have tried the below all commands.

mvn clean install -Pprofile1,profile2
mvn clean install -P profile1,profile2

when I use the above commands to build the project, XYZ has updating in all the modules. Similarly, when I use the below commands ABC is updating in all 4 modules.

mvn clean install -Pprofile2,profile1
mvn clean install -P profile2,profile1

My requirement is to update ABC only in module1 and module2, XYZ in module3 and module4. Could you please tell me, any solution which will solve this problem.

Note: I have even tried for the below command, mvn clean install -Pprofile1 -Pprofile2 Build has failed with goal or life cycle issue.

-Thanks


回答1:


The property in your aggregator is unique. So with your configuration, one profile overrides the other.

The solution in your case is to take the property out of the profile:

Aggregator:

<profiles>
  <profile>
     <id>profile1</id>
     <modules>
        <module>module1</module>
        <module>module2</module>
     </modules>
 <profile>
 <profile>
     <id>profile2</id>
     <modules>
        <module>module3</module>
        <module>module4</module>
     </modules>
  <profile>
</profiles>

Module 1 and 2 (no profile):

 <properties>
      <owner>ABC</owner>
 </properties>

Module 3 and 4 (no profile):

 <properties>
      <owner>XYZ</owner>
 </properties>

Since in your case the properties are always the same for each respective module.

However

As khmarbaise already wrote, your usage of profile seems somewhat odd...



来源:https://stackoverflow.com/questions/48002535/one-profile-properties-are-overriding-with-another-profile-properties-in-maven

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