在Maven的编译阶段始终显示当前活动的概要文件
我有一个Spring启动应用程序,它支持两个配置文件:dev和release。显然,在Maven的编译阶段始终显示当前活动的概要文件,maven,spring-boot,Maven,Spring Boot,我有一个Spring启动应用程序,它支持两个配置文件:dev和release。显然,dev配置文件在本地工作时使用,而release配置文件在服务器上实际部署应用程序时被Jenkins用作CI/CD管道的一部分 配置文件定义 <profiles> <profile> <id>dev</id> <properties> <activatedProperties>d
dev
配置文件在本地工作时使用,而release
配置文件在服务器上实际部署应用程序时被Jenkins用作CI/CD管道的一部分
配置文件定义
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>release</id>
<properties>
<activatedProperties>release</activatedProperties>
</properties>
</profile>
</profiles>
所以我可以在Jenkins管道脚本中使用它
mvn clean compile -Prelease help:active-profiles
这很有效。但是,我想知道是否有一种方法可以在编译阶段始终运行help:activeprofiles
goal,这样所有开发人员都可以清楚地看到他们使用的配置文件
谢谢您可以添加Maven帮助插件,如下所示:
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>print-profile</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
您可能可以将maven帮助插件的执行添加到编译阶段(在pom.xml中)。谢谢你,工作很好。使用EclipseMars时,我在
执行
行上收到了一条警告,抱怨如下:生命周期配置未涵盖插件执行:org.apache.maven.plugins:maven帮助插件:2.2:活动配置文件(执行:打印配置文件,阶段:编译)
。看起来是m2e的小故障。我已经点击了永久性标记目标活动配置文件为忽略,它的工作原理与它应该的一样。
<plugin>
<artifactId>maven-help-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>print-profile</id>
<phase>compile</phase>
<goals>
<goal>active-profiles</goal>
</goals>
</execution>
</executions>
</plugin>
[INFO] --- maven-help-plugin:2.2:active-profiles (print-profile) @ testProject ---
[INFO]
Active Profiles for Project 'com.test.testProject:jar:1.0.0-SNAPSHOT':
The following profiles are active:
- sonar (source: external)
- release (source: external)
- dev (source: com.test.testProject:jar:1.0.0-SNAPSHOT)