2
votes

Inside my module build script (build.gradle) I can set dependencies:

dependencies {
    compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
}

Gradle Example 8.2

I can also use buildscript() method inside the build script and set dependencies:

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'
    }
}

Gradle Example 59.6

My question, are these the same? Is there any difference between these two ways of setting dependencies for the build script?

1

1 Answers

7
votes

There is a big difference. The former declares (compile) dependencies of your code; the latter declares dependencies of the build script itself (i.e. it allows to use commons-codec right in the build script).