Gradle global variable not in scope within buildscript

前端 未结 2 1529
独厮守ぢ
独厮守ぢ 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: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
            }
        }
    }
    

提交回复
热议问题