我有一个Spring Boot Gradle项目,该项目具有基于不同环境的多个属性,例如application-dev.properties
,application-prod.properties
等。
我想做的是,根据环境arg建立一个只有一个application.properties
文件的war文件。
我有以下使用processResources
的代码
processResources {
def profile = (project.hasProperty('profile') ? project.profile : 'prod').toLowerCase()
include "**/application-${profile}.properties"
rename {
'application.properties'
}
}
我唯一遇到的问题是,这不包括资源文件夹中的所有静态文件。例如,在我的资源文件夹中,我有静态文件夹,模板文件夹和一些其他静态文件。任何帮助将非常感激。
最佳答案
我的方法是使用doFirst替换环境的属性。
像这样
war {
doFirst {
def propertyFile = file("build/resources/main/env_${branch}.properties")
if(propertyFile.exists()){
delete 'build/resources/main/env.properties'
propertyFile.renameTo(file("build/resources/main/env.properties"))
}
}}
关于java - Gradle基于环境属性构建War文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47101269/