问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/24783070/gradle-build-spring-boot-app-as-war-with-active-profile