Gradle global variable not in scope within buildscript

前端 未结 2 1526
独厮守ぢ
独厮守ぢ 2021-01-17 16:27

I have something like this in my top level build.gradle (Gradle 2.2)

ext.repo = \"https://my-artifactory-repo\"

buildscript {
    repositories          


        
相关标签:
2条回答
  • 2021-01-17 17:03

    This is happening because the buildscript {...} configuration closure is always evaluated first, so the property is not yet defined. A workaround would be to define the property outside of the build script, either by placing it in a gradle.properties file or via the command line.

    0 讨论(0)
  • 2021-01-17 17:14

    You can define your variable as an extra property with ext in the buildscript {...}. This variable is then also accessible in the scope of allprojects {...}:

    buildscript {
        ext {
            repo = "https://my-artifactory-repo"
        }
        repositories {
            maven {
                url repo // works
            }
        }
    }
    
    allprojects {
        repositories {
            maven {
                url repo // works
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题