Include of buildscript repository definition fails

2019-08-05 13:37发布

问题:

I have multiple files in my gradle build. In one file, I define my repositories. For example, repos.gradle looks like:

buildscript {
    repositories {
        maven {
            url "nexus url"
        }
    }
}

Now, in my projects build script, my project.gradle looks like:

apply from: "repos.gradle"

buildscript {
    dependencies {
        classpath "some:library:version"
    }
}

This fails to build, with an error along the lines of unable to add dependency because no repositories are defined. If I define everything in the project.gradle file, everything works.

How can I inherit the repository definition? I have many many projects, and want to use the one definition in case it changes.

回答1:

The buildscript information can't be put into a separate file (here repos.gradle) and then imported, it's a special block.

What you can do on the other hand is to put your buildscript block into the top level build.gradle file and then all other build files from subprojects/inclusion will inherit this block.