One profile properties are overriding with another profile properties in maven?
Asked Answered
H

1

2

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

Hereof answered 28/12, 2017 at 6:19 Comment(6)
First why do you need having profiles for different modules? (Suggestion: Never use profiles for modules!)...Administer
We have two projects to build two ears with different properties. Those properties has to place accordingly where it is required.Hereof
If you have to build two ear's you should simply have two ear module...that will solve the issue simply..Administer
You are not understanding my problem khmarbaise. It's not the problem with building ear files. It's problem with replacing the property values where all it's required at the time of building ear files. Read description once again and let me know if you have any queries.Hereof
Where exactly is the property needed to be replaced and for what purpose ? Why are their two modules involved and not only the EAR module?Administer
We have built an application which will support to multiple other projects. Mostly source code will be common for all projects except the JNDI names and few other properties. When I run individual profiles, it is placing proper properties across the application where it is required. But, the problem is when I place multiple profiles with comma separated, it is not setting individual properties. It is overriding one profile proper ties with other profile properties values. I hope this will be clear.Hereof
L
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...

Lymphocyte answered 7/1, 2018 at 20:42 Comment(1)
Even I have configured properties in module level it is not replacing proper values in output file. Do you have any other solution?Hereof

© 2022 - 2024 — McMap. All rights reserved.