简体   繁体   English

如何通过命令行将参数传递给 maven settings.xml?

[英]How to pass arguments via command line to maven settings.xml?

I need to activate profiles based on environment specifics in Spring Boot Maven application.我需要根据 Spring Boot Maven 应用程序中的环境细节激活配置文件。 I configured profiles in settings.xml我在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>

I tried by activating the profiles using commands -Pdev我尝试使用命令-Pdev激活配置文件

mvn spring-boot:run -s settings.xml -D"spring-boot.run.profiles"=dev help:active-profiles

But profiles are not activated properly.但配置文件未正确激活。 But It's working by adding activeprofiles tags.但它是通过添加activeprofiles标签来工作的。

    <activeProfiles>
        <activeProfile>dev</activeProfile>
    </activeProfiles>

But I need to activate the profiles environment specific like但我需要激活特定于的配置文件环境

    <activeProfiles>
        <activeProfile>$env</activeProfile>
    </activeProfiles>

Any way we can pass arguments to activeProfile in settings.xml file?我们可以通过任何方式将参数传递给 settings.xml 文件中的activeProfile吗? Similar like this -Denv类似这样-Denv

Reference:参考:

Maven: How do I activate a profile from command line? Maven:如何从命令行激活配置文件?

Configure active profile in SpringBoot via Maven 通过 Maven 在 SpringBoot 中配置活动配置文件

https://mkyong.com/maven/maven-profiles-example/ https://mkyong.com/maven/maven-profiles-example/

http://maven.apache.org/settings.html http://maven.apache.org/settings.html

Pay attention to this line of description: "Activation occurs when all specified criteria have been met, though not all are required at once."请注意这一行描述:“当满足所有指定的条件时会发生激活,但并非同时需要所有条件。” from http://maven.apache.org/settings.html in Profiles section and consider to define application.properties in your project and add line with this config: spring.profiles.active=@spring.profiles.active@ I hope this work.http://maven.apache.org/settings.html在 Profiles 部分并考虑在您的项目中定义 application.properties 并添加带有此配置的行: spring.profiles.active=@spring.profiles.active@ 我希望这个工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM