Gradle build spring boot app as war with active profile

为君一笑 提交于 2019-12-04 03:41:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!