2017-02-07 1 views
0

다음과 같은 gradle 작업이 있습니다. 빌드를 시작하기 전에 GOPATH 설정하기. 두 번째 작업을 실행하면 runUnitTest와 GOPATH가 해당 블록 내에 설정되지 않고 "$ GOPATH not set"오류가 표시됩니다.Gradle의 전역 변수 선언

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" 

} 

물론 두 번째 작업 내에서 GOPATH를 다시 ​​설정할 수 있습니다. 그러나 전 세계적으로 gradle을 설정하는 방법에 대해 궁금합니다.

답변

1

당신은 유형 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%" 
} 
+0

작품 .. 감사합니다. –