[英]How to pass arguments via command line to 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>
我们可以通过任何方式将参数传递给 settings.xml 文件中的activeProfile
吗? 类似这样-Denv
参考:
通过 Maven 在 SpringBoot 中配置活动配置文件
请注意这一行描述:“当满足所有指定的条件时会发生激活,但并非同时需要所有条件。” 从http://maven.apache.org/settings.html在 Profiles 部分并考虑在您的项目中定义 application.properties 并添加带有此配置的行: spring.profiles.active=@spring.profiles.active@ 我希望这个工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.