如何根据命令行参数将文件复制到WAR类路径中?

时间:2015-11-16 18:17:04

标签: gradle build classpath environment

我正在使用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文件复制到类路径中。

1 个答案:

答案 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添加到源集,则可以使用它而不是路径。