与“buildscript.repositories”共享Gradle“存储库”

时间:2016-06-25 02:39:46

标签: gradle

我希望我在repositories块中指定的buildscript.repositories与依赖项repositories块的相同存储库相同。请看我的例子:

正常buidldscript

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:2.1.2"
    }
}

repositories {
    jcenter()
}

我该如何做以下事情?

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:2.1.2"
    }
}

repositories = buildscript.repositories

1 个答案:

答案 0 :(得分:3)

根据这个question and answer,你只需先在变量中声明它:

buildscript {
    ext.myRepos = {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    repositories myRepos

    dependencies {
        classpath "com.android.tools.build:gradle:2.1.2"
    }
}

repositories myRepos

理想情况下,我想使用plugins { }块,但Android gradle插件不在plugins.gradle.org上。

buildscript {
    configure([buildscript.repositories, project.repositories]) {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "com.android.tools.build:gradle:2.1.2"
    }
}