gradle编译java springboot,指定使用哪个环境配置文件
首先在build.gradle里面声明一个变量
def profileName = project.hasProperty("profile") ? project.property("profile") : "test"
processResources {
filter org.apache.tools.ant.filters.ReplaceTokens, tokens: [profileName: profileName]
}
同时在application.properties 里面引用该变量
spring.profiles.active=@profileName@
在编译时添加参数即可,如下例所示,在对正式环境打包时使用applicattion-prod配置文件
gradle clean build -Pprofile=prod