Maven Profiles
验证:未记录
- 适用版本
- 未记录
- 验证范围
- 尚未登记验证记录。
本文缩写(英文全称与中文含义)
| 缩写 | 英文全称/名称 | 中文含义 |
|---|---|---|
| CI | Continuous Integration | 持续集成 |
| CLI | Command-Line Interface | 命令行接口 |
| JDK | Java Development Kit | Java 开发工具包 |
| POM | Project Object Model | Maven 项目对象模型 |
Links#
https://maven.apache.org/guides/introduction/introduction-to-profiles.html
https://maven.apache.org/ref/current/maven-model/maven.html#profiles1. Important Points#
Maven profile 用于构建差异,不作为生产 Secret 或普通应用运行配置的存储位置。
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 config2. CLI Activation#
<profiles>
<profile>
<id>prod</id>
<properties>
<build.env>prod</build.env>
</properties>
</profile>
</profiles>./mvnw -Pprod clean package
./mvnw help:active-profiles3. 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 verify4. 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 jobs6. activeByDefault#
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>activeByDefault:
disabled when another profile in the same POM is explicitly activated7. Maven Profile vs Spring Profile#
./mvnw -Pprod clean package
java -jar app.jar --spring.profiles.active=prodMaven profile:
affects build
Spring profile:
affects runtime application configuration8. 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