This is my first day using Maven's build profiles. I have profiles in following files:
For curiosity I have created one profile in both files with same id(local_deploy), only difference being in one property (e.g. tomcat.pwd).
Profile in POM looks like below:
<profile>
<id>local_deploy</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<tomcat.host>localhost</tomcat.host>
<tomcat.port>8080</tomcat.port>
<tomcat.url>http://${tomcat.host}:${tomcat.port}/manager/text</tomcat.url>
<tomcat.user>admin</tomcat.user>
<tomcat.pwd>admin</tomcat.pwd>
</properties>
</profile>
Profile in Maven setting looks like below:
<profile>
<id>local_deploy</id>
<properties>
<tomcat.host>localhost</tomcat.host>
<tomcat.port>8080</tomcat.port>
<tomcat.url>http://${tomcat.host}:${tomcat.port}/manager/text</tomcat.url>
<tomcat.user>admin</tomcat.user>
<tomcat.pwd>wrongpwd</tomcat.pwd>
</properties>
</profile>
Please note, Profile in Maven setting is not listed in <activeProfiles>
.
When I try to install my application using following command
mvn clean install -P local_deploy help:active-profiles
My application gets deployed with following output on console:
The following profiles are active:
local_deploy (source: external)
local_deploy (source: <my groupId>:<my artifactId><version>)
I am going through this documentation and it says that
Take note that profiles in the settings.xml takes higher priority than profiles in the POM
So, I assume my deployment should have failed because of incorrect password in Maven Setting. What am I missing here?
Here is a sample pom I used:
<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>com.sample</groupId>
<artifactId>profiles-sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>print-hello</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<property name="msg" value="${hello}" />
<property name="msg2" value="${hello2}" />
<echo message="hello from build: ${msg}, ${msg2}" />
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>p2</id>
<properties>
<hello>from-pom</hello>
<hello2>from-pom-again</hello2>
</properties>
</profile>
</profiles>
</project>
Defining in my settings:
<profile>
<id>p2</id>
<properties>
<hello>from-settings</hello>
</properties>
</profile>
So, note: two profiles with the same name, on POM and settings, defining the same hello
property. However, the one in the POM defines one additional property, hello2
.
Then, running:
mvn test -Pp2 help:active-profiles
I got as part of the build output:
[INFO] --- maven-antrun-plugin:1.5:run (print-hello) @ profiles-sample ---
[INFO] Executing tasks
main:
[echo] hello from build: from-settings, from-pom-again
[INFO] Executed tasks
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building profiles-sample 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:active-profiles (default-cli) @ profiles-sample ---
[INFO]
Active Profiles for Project 'com.sample:profiles-sample:jar:0.0.1-SNAPSHOT':
The following profiles are active:
- p2 (source: external)
- p2 (source: com.sample:profiles-sample:0.0.1-SNAPSHOT)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
So, from the Maven Help Plugin we actually know that both profiles were actives and that's true, because as part of the Antrun we got both properties (hello
from the profile of the settings and hello2
from the profile of the pom).
Hence, the two profiles were actives at the same time, their properties got merged (because hello
is sharing the same name), the property from the settings took priority over the property from the POM, then the additional property of the POM got correctly in as well.
So, I couldn't reproduce the scenario you mentioned. I would suggest to double check settings and pom and add an additional property to play with.