I have two profiles that are nearly identical. Rather than duplicating the configuration in each, I'd like for one profile to "inherit" from the other, but I don't see an obvious way to do this using maven 3.
Is profile inheritance possible in maven?
No, profiles cannot be inherited.
However, you can have multiple active profiles, which could allow you to accomplish roughly the same thing by factoring out the common elements in the two profiles into a third profile that you activate whenever you activate one of the other two profiles.
Strictly speaking profiles are not inherited in that profiles defined in a parent pom are not available in child poms, as per maven documentation. HOWEVER, properties and build plugins (not pluginManagement) that are specified in parent poms can get activated and hence modify the build environment for the child poms. For example if I have a parent pom A, which has the following profiles section:
</profiles>
<profile>
<id>integrationTest</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<parallel>none</parallel>
<excludes>
<exclude>**/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes
<include>**/*IT.java</include>
</includes>
<!-- need to exclude nothing as it is possible that some by default some tests are excluded and we need to override that -->
<excludes>
<exclude>none</exclude>
</excludes>
<parallel>none</parallel>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
And then a child pom B which doesn't have failsafe plugin configured in the default build but inherits from A pom via the parent tag and I then run 'mvn clean install -P integrationTest' from the child pom directory, it will take the plugin information specified in A.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With