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' }
compile is the group of dependencies you need to build your application while testCompile is a group of dependencies that you need only for testing. This specifies that hibernate-core is needed to build your code but junit (a testing framework) is needed just for testing.
Gradle build script defines a process to build projects; each project contains some dependencies and some publications. Dependencies refer to the things that supports in building your project, such as required JAR file from other projects and external JARs like JDBC JAR or Eh-cache JAR in the class path.
Fortunately, the implementation dependency configuration provides the same functionality as compile. You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.
compile-time classpath. Contains the classes that you've added in your IDE (assuming you use an IDE) in order to compile your code. In other words, this is the classpath passed to “javac” (though you may be using another compiler). runtime classpath. Contains the classes that are used when your application is running.
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
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 buildSrc {}
block where one needs to declare dependencies for the build.gradle, itself (for plugins, perhaps).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With