padfoot
padfoot

Reputation: 851

How does gradle get the library

I always see when you add lines like compile 'joda-time:joda-time:2.9.2' in gradle, say in Android Studio, it gets the library automatically and uses it in my project. How does this happen? How does gradle find the library and get it and links it?

Upvotes: 1

Views: 992

Answers (1)

Gabriele Mariotti
Gabriele Mariotti

Reputation: 365008

Gradle allows you to tell it what the dependencies of your project are, so that it can take care of finding these dependencies, and making them available in your build.
The dependencies might need to be downloaded from a remote Maven or Ivy repository, or located in a local directory, or may need to be built by another project in the same multi-project build

You can read more info in the official doc.

First of all you have to declare the repositories from which you want to download the dependencies:

Somenthing like:

repositories {
    mavenCentral()
    jcenter()
    maven {
        url "http://repo.mycompany.com/maven2"
    }
}

The repository can be public or private, and you can define more than 1 repo. It is important the order.

Then you can declare your dependencies:

dependencies{
     //..
     compile 'joda-time:joda-time:2.9.2'    
}

Each artifact has a pom file which describes some properties (for example the name and the version) and the nested dependencies.
Gradle downalod the artifact and the nested dependencies for you, using this pom file.

Here you can find the files and the pom file for the joda-time library in jcenter repo.

Upvotes: 2

Related Questions