Gradle: What is the difference between classpath and compile dependencies?

java123999 picture java123999 · Dec 15, 2015 · Viewed 63.9k times · Source

When adding dependencies to my project I am never sure what prefix I should give them, e.g. "classpath" or "compile".

For example, should my dependencies below be compile time or classpath?

Also, should this be in my applications build.gradle or in the module specific build.gradle?

Current build.gradle (at application level):

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.hibernate:hibernate-core:5.0.5.Final'
    compile 'mysql:mysql-connector-java:5.1.38'
} 

Answer

q... picture q... · Jan 10, 2017

If buildscript itself needs something to run, use classpath.

If your project needs something to run, use compile.

The buildscript{} block is for the build.gradle itself.

For multi-project building, the top-level build file is for the root project, the specific build file is for sub-project (module).

Top-level build file where you can add configuration options common to all sub-projects/modules.

Do not place your application dependencies in top-level build file, they belong in the individual module build.gradle files