'Inheriting Maven profiles and activation
My maven project defines a profile with activation condition and has a child module. The activation condition of the parent project is ignored and I have to copy it to the child.
Parent:
<profiles>
<profile>
<id>container</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>local</id>
<activation>
<property>
<name>spring.profiles.active</name>
<value>local</value>
</property>
</activation>
</profile>
</profiles>
Child:
<profiles>
<profile>
<id>local</id>
<!-- Remove comments and it will work: -->
<!--
<activation>
<property>
<name>spring.profiles.active</name>
<value>local</value>
</property>
</activation>
-->
<dependencies>
<!-- (...) --->
</dependencies>
</profile>
</profiles>
Then I run
mvn package -Dspring.profiles.active=local -P !container
and the dependecies of profile "local" are missing in the artifacts. If I remove the comments around the activation, the dependencies are available. The result equal when I run mvn package from the parent and from the child project's directory.
Strange thing is that help:active-profiles says the profile is avaiable if the activation is commented out in the child, as expected:
C:\myproject> cd child
C:\myproject\child> mvn help:active-profiles -Dspring.profiles.active=local -P !container
(...)
The following profiles are active:
- local (source: org.example:myproject:1.0.0-SNAPSHOT)
What is wrong here?
Solution 1:[1]
It is likely that profiles are not merged with the one in the parent, but that a profile with the same name completely overrides the profile from the parent.
So your construction will probably not work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | J Fabian Meier |
