【问题标题】:Gradle build war file based on environment propertiesGradle 基于环境属性构建war文件
【发布时间】:2017-11-03 17:22:35
【问题描述】:

我有一个 Spring Boot Gradle 项目,它具有基于不同环境的多个属性,例如 application-dev.propertiesapplication-prod.properties 等。

我想做的是,基于环境 arg 构建一个只有一个 application.properties 文件的 war 文件。

我有以下使用processResources

processResources {
    def profile = (project.hasProperty('profile') ? project.profile : 'prod').toLowerCase()
    include "**/application-${profile}.properties"
    rename {
        'application.properties'
    }
}

我遇到的唯一问题是,这不包括资源文件夹中的所有静态文件。例如,在我的资源文件夹中,我有静态文件夹、模板文件夹和其他一些静态文件。任何帮助将非常感激。

【问题讨论】:

    标签: java spring spring-boot gradle


    【解决方案1】:

    我的做法是使用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"))
        }
    }}
    

    【讨论】:

      猜你喜欢
      • 2015-11-18
      • 2017-02-12
      • 2019-02-18
      • 1970-01-01
      • 2011-06-28
      • 2018-01-23
      • 2015-04-18
      • 2019-11-03
      • 2018-08-08
      相关资源
      最近更新 更多