Links#
https://maven.apache.org/guides/introduction/introduction-to-profiles.html
https://maven.apache.org/ref/current/maven-model/maven.html#profiles
1. Important Points#
profile:
conditional build configuration
use profile for:
build-time differences
repository selection
plugin execution switch
package classifier or resource filtering
do not use profile for:
production secret
normal application runtime config
2. CLI Activation#
<profiles>
<profile>
<id>prod</id>
<properties>
<build.env>prod</build.env>
</properties>
</profile>
</profiles>
./mvnw -Pprod clean package
./mvnw help:active-profiles
3. Property Activation#
<profile>
<id>coverage</id>
<activation>
<property>
<name>coverage</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</profile>
./mvnw -Dcoverage=true clean verify
4. JDK Activation#
<profile>
<id>jdk21</id>
<activation>
<jdk>[21,)</jdk>
</activation>
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
</profile>
5. File Activation#
<profile>
<id>local-extra</id>
<activation>
<file>
<exists>local.properties</exists>
</file>
</activation>
</profile>
file activation:
useful for local-only build behavior
do not depend on it in CI release jobs
6. activeByDefault#
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
activeByDefault:
disabled when another profile in the same POM is explicitly activated
7. Maven Profile vs Spring Profile#
./mvnw -Pprod clean package
java -jar app.jar --spring.profiles.active=prod
Maven profile:
affects build
Spring profile:
affects runtime application configuration
8. Checklist#
check:
profile purpose is build-time
active profile is visible in CI logs
profile does not hide required tests
secrets are not stored in profile properties
final result is verified with effective-pom