0

I need to activate profiles based on environment specifics in Spring Boot Maven application. I configured profiles in 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

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>
        <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? Similar like this -Denv

Reference:

Maven: How do I activate a profile from command line?

Configure active profile in SpringBoot via Maven

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

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

Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99
Debugger
  • 690
  • 1
  • 18
  • 41

1 Answers1

0

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.