Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build spring boot app as war with active profile

I would like to package my spring boot application as war for a specific profile. That can be done with setting spring.profiles.active=profile name in application.properties file. Is it possible to set it as a parameter when building war eg. gradle build --spring.profiles.active=profile name?

like image 682
stamis Avatar asked Jul 16 '14 14:07

stamis


1 Answers

It sounds like you want to bake the value of spring.profiles.active into the war when it's built. You can do so using Gradle's support for resource filtering. Configure your application.properties like this:

spring.profiles.active=@activeProfiles@

And then apply filtering in your build.gradle to replace @activeProfiles@ with the value of a property:

processResources {
    filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [
        activeProfiles: activeProfiles
    ]
}

In this example, I've used a property named activeProfiles. You'd then have to supply a value when you run the build:

./gradlew -PactiveProfiles=foo build
like image 186
Andy Wilkinson Avatar answered Nov 29 '22 19:11

Andy Wilkinson