Do some profile properties override other profile properties in maven?

I have a problem with maven profiles. Coming to the details, I have two profiles, such as profile1 and profile2. I declared several properties for both profiles, along with modules that need to be updated for each profile separately. Check out the configuration below.

<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> 

Returning to the point, the profile1 property of ABC should be updated in module1, and the module2 property and XYZ profile2 property should be updated in module 3 and module4. When creating the application, I tried the following commands:

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

when I use the above commands to create a project, XYZ has an update in all modules. Similarly, when I use the commands below, ABC updates all 4 modules.

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

My requirement is to update ABC only in modules 1 and module2, XYZ in module3 and module4. Please tell me any solution that will solve this problem.

Note. I even tried to run the command below, mvn clean install -Pprofile1 -Pprofile2 The assembly failed with a target or life cycle problem.

-Thanks

+1
maven maven-profiles
source share
1 answer

The property in your aggregator is unique. Thus, with your configuration, one profile overrides another.

The solution in your case is to derive the property from 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 (without profile):

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

Module 3 and 4 (without profile):

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

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

but

As khmarbaise already wrote, your use of the profile seems a little strange ...

+1
source share

All Articles