7

我想将我的 Spring Boot 应用程序打包为特定配置文件的战争。这可以通过在 application.properties 文件中设置 spring.profiles.active= profile name来完成。是否可以在构建战争时将其设置为参数,例如。gradle build --spring.profiles.active=配置文件名称

4

1 回答 1

12

听起来您想spring.profiles.active在战争建成时将其价值融入战争中。您可以使用 Gradle 对资源过滤的支持来执行此操作。像这样配置你application.properties

spring.profiles.active=@activeProfiles@

然后在您的应用过滤build.gradle以替换@activeProfiles@为属性的值:

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

在此示例中,我使用了一个名为activeProfiles. 然后,您必须在运行构建时提供一个值:

./gradlew -PactiveProfiles=foo build
于 2014-07-16T15:30:02.460 回答