Purpose of buildscript block in Gradle

I am new to Gradle and I am reading the documentation but I don’t understand some parts of it. One of these parts is connected with buildscript block. What is its purpose?

If your build script needs to use external libraries, you can add them to the script’s classpath in the build script itself. You do this using the buildscript() method, passing in a closure which declares the build script classpath.

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath group: 'commons-codec', name: 'commons-codec', version: '1.2'
  }
}

Ok but what is the difference with:

repositories {
  mavenCentral()
}
dependencies {
  compile group: 'commons-codec', name: 'commons-codec', version: '1.2'
}

For example, why it is necessary to use buildscript?

7 Answers
7

Leave a Comment