Dependencies
Last updated
Was this helpful?
Last updated
Was this helpful?
Before we start adding dependencies, we need to say what plugis are going to be used. For Java project, we first have to apply Java plugin and then we can provide dependencies.
We can specify version using +. That will make sure that always highest version of that version level is used. Suppose we use .
We can takes all jars for given configuration and copies it into a specific folder. The following task is going to take all compile
dependencies and copy it into to copied
folder.
We can then reuse all jar files in a folder and add them into a scope.
Add dependency without its transitive dependencies.
Dominate a certain version, including transitive dependencies, over others.
Exclude a certain transitive dependency.
Add jar into compile configuration.
Add all jars from a folder into compile configuration.
We can have dependencies on other sub-modules or aka projects.
We can obtain dependencies from multiple repository types.
Gradle tries to connect to repositories to check if the dependencies are up to date. We can turn all interactions with network using --offline
flag.
We can create our own task to print all dependencies for a specific scope.
Other way to check dependencies is to use dependencies and dependencyInsight tasks that are provided by Gradle.
When using many libraries, there can be version conflicts of some libraries. We can force certain version of a library for our project.
If we want to be strict and we want to avoid version conflicts, we might want to say Gradle to fail build if there is a version conflict.
When working with SNAPSHOTs, we might want to force Gradle to reload dependencies.
We can refresh dependencies using --refresh-dependencies flag.
Or we can change caching times.
We might need to create our own configuration (a bucket) to place our files (dependencies).This example shows how compile configuration can be created and used.
For example Java plugin provides six configurations: archives, default, compile, runtime, testCompile testRuntime.
Configurations can extend from other configurations.