我正在使用Gradle 2.7。我的构建“
中有以下文件src/main/environment/dev/aws.properties
src/main/environment/qa/aws.properties
src/main/environment/prod/aws.properties
如何根据是否有人在执行构建时在命令行上指定环境(例如gradle build -Penv=qa
),将文件复制到我的汇编WAR类路径中?如果未指定-Penv=xxx
标志,我希望将src/main/environment/dev/aws.properties
文件复制到类路径中。
答案 0 :(得分:0)
它将是:
war {
def env = project.hasProperty('env') ? project.env : 'dev'
from("src/main/environment/$env") {
include('aws.properties')
into('WEB-INF/classes')
}
}
如果您在其他地方需要env
,则可以在脚本的开头定义它。如果您已将src/main/environment
添加到源集,则可以使用它而不是路径。