java - 如何通过命令行将参数传递给 maven settings.xml?
问题描述
我需要根据 Spring Boot Maven 应用程序中的环境细节激活配置文件。我在settings.xml中配置了配置文件
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>false</activeByDefault> </activation>
<repositories>
<repository>
<id>devRepo</id>
<url>https://customRepo/maven/v1</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>qa</id>
<activation>
<activeByDefault>false</activeByDefault> </activation>
<repositories>
<repository>
<id>qaRepo</id>
<url>https://customRepo2/maven/v1</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
我尝试使用命令激活配置文件-Pdev
mvn spring-boot:run -s settings.xml -D"spring-boot.run.profiles"=dev help:active-profiles
但配置文件未正确激活。但它通过添加activeprofiles
标签来工作。
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
但是我需要激活特定的配置文件环境,例如
<activeProfiles>
<activeProfile>$env</activeProfile>
</activeProfiles>
我们可以通过任何方式将参数传递给activeProfile
settings.xml 文件吗?类似这样-Denv
参考:
通过 Maven 在 SpringBoot 中配置活动配置文件
解决方案
请注意这行描述:“激活发生在所有指定条件都已满足时,但并非所有条件都需要一次。” 从配置文件部分中的http://maven.apache.org/settings.html 并考虑在您的项目中定义 application.properties 并使用此配置添加行: spring.profiles.active=@spring.profiles.active@ 我希望这个工作。
推荐阅读
- mysql - SQL查询到laravel?
- java - Java - 实例变量取决于构造函数参数
- android - 如何查看本地分支和以前的提交
- java - 在Java中使用按ID号的链表升序
- fusionauth - oauth2/logout 用户是否使发给用户的任何刷新令牌失效
- shiny - Dashboard Shiny:刷机无表更新
- azure - Azure 虚拟机规模集 VMSS 重新映像而不中断服务
- reactjs - 如何在javascript中正确制作div选项卡以与reactjs一起使用
- javascript - 在 javascript 中,匹配没有按预期的方式工作
- python - 无法再找到附加到谷歌云实例的 GPU