简体   繁体   English

gradle如何定义jar文件的相关jar文件?

[英]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. 当我通过gradle运行以上依赖项时,它将下载jar文件和相关的其他jar文件。

My question is: How gradle defines which jars are required for this jar? 我的问题是: gradle如何定义此罐子需要哪些罐子?

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 您可以在这里找到更多详细信息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 默认情况下,它通过遍历pom文件来使用标准的maven依赖关系解析策略

For example in your case of org.glassfish.jersey.media it gets the POM file from here . 例如,对于org.glassfish.jersey.media,它是从此处获取POM文件的。 This POM file contains the following dependencies section. 该POM文件包含以下依赖项部分。 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. gradle加载此文件后,它依次加载相应的POM文件并查看依赖关系的依赖关系,直到到达不依赖任何内容的叶子包。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM