Search code examples
javagradledependencies

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


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

Solution

  • I'm going to guess that you're referencing compile and classpath within the dependencies {} block. If that is so, those are dependency Configurations.

    A configuration is simply a named set of dependencies.

    The compile configuration is created by the Java plugin. The classpath configuration is commonly seen in the buildScript {} block where one needs to declare dependencies for the build.gradle, itself (for plugins, perhaps).