drdl18946 2017-02-07 21:37
浏览 419
已采纳

Gradle上的全局变量声明

I have a gradle task as follows. Setting the GOPATH before I start the build. When I run the second task, that is runUnitTest and GOPATH is not set inside that block and I see this error "$GOPATH not set".

task goBuild(type:Exec) {
  environment 'GOPATH', projectDir.toString().split("/src")[0]
  commandLine "go", "build", "main.go"
}

task runUnitTest(type:Exec) {
  dependsOn goBuild
  commandLine "go", "get", "github.com/AlekSi/gocov-xml"
  commandLine "go", "test", "-v"

}

I can of course, set the GOPATH again inside the second task. But, I am curious on how to have globally set in gradle.

  • 写回答

1条回答 默认 最新

  • duanshang3230 2017-02-07 22:12
    关注

    You can set the environmental property for all tasks of type Exec:

    tasks.withType(Exec) {
        environment 'GOPATH', 'hello'
    }
    
    task first(type:Exec) {
        commandLine 'CMD', '/C', 'echo', "%GOPATH%"
    }
    
    task second(type:Exec) {
        commandLine 'CMD', '/C', 'echo', "%GOPATH%"
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!