Introduction
I have a multi module maven project. The structure and further details are described below.
pom.xml
module-a
- src/main/resources/demo.properties
module-b
- pom.xml
- module-b1
- pom.xml
- src/main/resources/demo.properties
- module-b2
- pom.xml
- src/main/resources/demo.properties
- src/templates/active-by-default/
- src/templates/other-profile/
I am trying to achieve two things:
- (1) copy the content from the directory
src/templates/<some-folder-name>based on a specific profile to thetargetfolder ofmodule-b2 - (2) overriding properties for resource filtering.
Please note, that the full code example is available via GitHub.
Maven Setup
In this context, I have defined the <profiles> section in the root pom.xml as follows:
<profiles>
<profile>
<id>active-by-default-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<some.props>some-props-from-active-by-default</some.props>
</properties>
</profile>
<profile>
<id>other-profile</id>
<properties>
<some.props>some-props-from-other-profile</some.props>
</properties>
</profile>
</profiles>
In module-b1 I am overriding the given profile id's and override the property some.props from the parent pom.xml:
<profiles>
<profile>
<id>active-by-default-profile</id>
<properties>
<some.props>overridden-by-default-in-submodule-b1</some.props>
</properties>
</profile>
<profile>
<id>other-profile</id>
<properties>
<some.props>some-other-props-overridden-in-submodule-b1</some.props>
</properties>
</profile>
</profiles>
In module-b2 (there I want to copy files with the maven ant plugin in version 3.0.0) it looks like:
<profiles>
<profile>
<id>active-by-default-profile</id>
<properties>
<copy.source>${project.basedir}/src/templates/active-by-default/</copy.source>
</properties>
</profile>
<profile>
<id>other-profile</id>
<properties>
<copy.source>${project.basedir}/src/templates/other-profile/</copy.source>
</properties>
</profile>
</profiles>
Additional Output
Output of mvn help:active-profiles:
Active Profiles for Project 'org.example:issue-with-ant-plugin:pom:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-a:jar:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-b:pom:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-b1:jar:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-b2:jar:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Output of mvn help:active-profiles -Pactive-by-default-profile:
Active Profiles for Project 'org.example:issue-with-ant-plugin:pom:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-a:jar:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-b:pom:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-b1:jar:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:module-b1:1.0-SNAPSHOT)
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Active Profiles for Project 'org.example:module-b2:jar:1.0-SNAPSHOT':
The following profiles are active:
- active-by-default-profile (source: org.example:module-b2:1.0-SNAPSHOT)
- active-by-default-profile (source: org.example:issue-with-ant-plugin:1.0-SNAPSHOT)
Problem Statement
Executing mvn clean install results in a build failure as the related copy.source property cannot be resolved during the ant plugin execution. In addition, the property some.props is not overridden.
If I am going to specifiy the profile explicitly via mvn clean install -Pactive-by-default-profile everything works as expected.
If it matters: I am using Maven in version 3.6.3 on an Ubuntu 20.04 LTS system.
Question
- Why is the
activeByDefaultactiviation not propagated down to the related sub modules? (in the same way it is done via-P? - What is the rational behind it? Has it something to do with the limitations of POM inheritance?
- Do I need to add additional
<activation>blocks in every sub-module in which I intend to have an active by default profile? Are there other "workarounds" for this?