I have a multi-module maven project where the parent contains a profile definition, activates that profile (using activeByDefault), and the child is supposed to take into account the activated profile and modify its build accordingly. I have this setup because I want to skip certain parts of the child build (for development) by deactivating the profile. The problem is that the activation of the profile in the parent doesn't seem to propagate to the child.
In order to reproduce this, I created a small parent/child project, where the child project's build outputs a message if the activated-by-default
profile is active. I'm using maven 3.5.0
This is my parent pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>profiletest</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>parent</name>
<url>http://maven.apache.org</url>
<modules>
<module>../child</module>
</modules>
<profiles>
<profile>
<id>activated-by-default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
child pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>profiletest</groupId>
<artifactId>child</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>child</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>profiletest</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<profiles>
<profile>
<id>activated-by-default</id>
<build>
<plugins>
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<message>building with activated-by-default profile</message>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
When I run mvn help:active-profiles package
, even though the activated-by-default
profile is shown as active, its corresponding build section is not executed:
$ mvn help:active-profiles package
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent
[INFO] child
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:active-profiles (default-cli) @ parent ---
[INFO]
Active Profiles for Project 'profiletest:parent:pom:1.0-SNAPSHOT':
The following profiles are active:
- activated-by-default (source: profiletest:parent:1.0-SNAPSHOT)
Active Profiles for Project 'profiletest:child:jar:1.0-SNAPSHOT':
The following profiles are active:
- activated-by-default (source: profiletest:parent:1.0-SNAPSHOT)
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parent 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building child 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /date/mt/dev/projects/mvn-active-by-default/child/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ child ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ child ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /date/mt/dev/projects/mvn-active-by-default/child/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ child ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ child ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................. SUCCESS [ 0.001 s]
[INFO] child .............................................. SUCCESS [ 0.528 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.201 s
[INFO] Finished at: 2017-10-11T09:24:38+03:00
[INFO] Final Memory: 13M/208M
[INFO] ------------------------------------------------------------------------