Gradle-Android: Where is the classpath() coming from?

Here is the root build.gradle file of an android app. I want to ask where does the classpath() method is declared. I guess in Project but I cant find it in the reference.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The buildscript block is special because it is compiled and executed before the rest of the script to determine the classpath for the build itself. There are configurations and dependencies for this just as there are for the project. The classpath is just the configuration that is used for the buildscript to resolve dependencies (equivalent to compile for Java in your previous question). Unlike on the project, there are typically not any additional configurations beyond classpath.

The buildscript block is a ScriptHandler. There is a constant for classpath on that interface.

1 Like