SkyWalker
SkyWalker

Reputation: 29170

How gradle defines dependent jar files of a jar file?

dependencies {
    sources group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.22.2', classifier: 'sources'
}

When I run the above dependencies through gradle, It downloads the jar file and related other jar files.

My question is: How gradle defines which jars are required for this jar?

Upvotes: 0

Views: 73

Answers (1)

Vlad
Vlad

Reputation: 9481

It uses one of dependency resolution strategies defined in your project. You can find more details here https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

By default it uses standard maven dependency resolution strategy by walking through pom files

For example in your case of org.glassfish.jersey.media it gets the POM file from here. This POM file contains the following dependencies section. After gradle loads this file it in turn loads corresponding POM files and looks into dependencies of dependencies, until it reaches the leaf packages that don't depend on anything. Things might get more complicated when your dependencies graph is not a perfect tree and two different packages have the same dependency. These usually resolved if the versions of the common dependency is the same or both dependent packages can use common version. Otherwise you get into conflict and one of the above strategies is used to resolve it.

  <dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-common</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-entity-filtering</artifactId>
        <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>org.eclipse.persistence.moxy</artifactId>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
  </dependencies>

Upvotes: 1

Related Questions