I have the following 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mycompany</groupId>
<artifactId>resource-fail</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<foo.bar>BazBat</foo.bar>
</properties>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>Development</id>
<!--
<activation>
<activeByDefault>true</activeByDefault>
</activation>
-->
<properties>
<foo.bar>Development</foo.bar>
</properties>
</profile>
</profiles>
</project>
Notice that the activation
element on the profile
is commented out
I also have the following in src/main/java/application.properties
myproperty=${foo.bar}
So what I expect Maven to do is simply replace ${foo.bar}
with BazBat
, unless the Development profile is activiated, then I expect Maven to replace ${foo.bar}
with Development
When I run mvn package
it sets the value to BazBat
. Good, the resource filtering is working as expected.
However when I run mvn package -P Development
it sets the value to BazBat
To confuse things further, if uncomment the activation
element on the profile and run mvn package
it will set ${foo.bar}
to Development
I've even run mvn help:active-profiles package
to have it output the active profile name and under both scenarios above it says that the Development profile is active, but filtering still does not work without the activeByDefault
flag being set.
To sum up:
- Maven properly overrides properties with values from the profile if the profile is
activeByDefault
- Maven does not override the property if I activate the profile via the command line switch
What is going on?
My environment:
> mvn -version
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-14T11:29:23-06:00)
Maven home: C:\apache-maven-3.2.5
Java version: 1.8.0_65, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_65\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
Update: I've upgraded to the latest maven (3.3.3) - the problem persists. My new environment:
> mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T06:57:37-05:00)
Maven home: C:\apache-maven-3.3.3
Java version: 1.8.0_65, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_65\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"