简体   繁体   English

给定多个 maven 存储库,Gradle 将选择哪个依赖项?

[英]Which dependency will Gradle choose given multiple maven repository?

In Gradle project, we can define multiple remote / local Maven repository.在 Gradle 项目中,我们可以定义多个远程/本地 Maven 存储库。

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jCenter()
        maven { 
            url 'https://example1.mavenrepo.com/public'
        }
        maven {
            url "https://example2.mavenrepo.com/release"
        }
    }

    dependencies {
        classpath 'com.example.mydependencies:mylibrary:1.0.0'
    }
}

If mylibrary exist in all of Maven repo.如果mylibrary存在于所有 Maven 存储库中。 Which one will Gradle choose? Gradle会选择哪一款? Can I configure Gradle to only download mylibrary in certain Maven repo?我可以将 Gradle 配置为仅在某些 Maven 存储库中下载mylibrary吗?

As you can find in the doc 您可以在文档中找到

A project can have multiple repositories. 一个项目可以有多个存储库。 Gradle will look for a dependency in each repository in the order they are specified, stopping at the first repository that contains the requested module . Gradle将按照指定的顺序在每个存储库查找依赖项,并在包含所请求模块的第一个存储库处停止

I don't think there is a way to point to the gradlew to use particular repository or order it.我认为没有办法指向 gradlew 使用特定的存储库或订购它。 Gradlew by design uses a single repository for all dependencies. Gradlew 通过设计为所有依赖项使用单个存储库。 If any of them fail, the build fails.如果其中任何一个失败,则构建失败。 [Refer]: https://github.com/gradle/gradle/issues/7965 【参考】: https://github.com/gradle/gradle/issues/7965

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

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