前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Gradle构建时像Maven那样根据profile环境打包

Gradle构建时像Maven那样根据profile环境打包

作者头像
白石
发布2021-03-07 10:38:51
1.8K0
发布2021-03-07 10:38:51
举报
文章被收录于专栏:白石白石

Gradle构建时像Maven那样根据profile环境打包

Gradle中并没有直接类似Maven中的profiles支持,但是可以在processResources 任务中写一些脚本,通过传入的系统属性profile值来支持.

例如运行gradle build时,传入profile系统属性

  • 打包开发环境: gradlew build -Dprofile=dev
  • 打包测试环境: gradlew build -Dprofile=test
  • 打包生产环境: gradlew build -Dprofile=prod
代码语言:javascript
复制
//@wjw_note: 根据传进来的profile系统属性来打包.
//def profileName = System.getProperty("profile") ?: "dev"
def profileName = System.getProperty("profile")
if(profileName==null) {
  throw new BuildCancelledException("must pass The environment variable 'profile'\r\n"
                                   +"For example: gradlew clean build -i -x test --no-daemon -Dprofile=dev")
}
processResources {
    include '**/public/**'
    include '**/static/**'
    include '**/templates/**'
    include '**/tpl/**'
    
    include { FileTreeElement details ->
        details.isDirectory()==true || details.file.name.contains("-${profileName}.")  /* 根据传入的profileName系统属性来过滤 */
    }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Gradle构建时像Maven那样根据profile环境打包
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档