简体   繁体   English

Gradle:根据Maven Local或Remote存储库中的最新版本解决SNAPSHOT依赖性

[英]Gradle: resolve SNAPSHOT-dependency based on most recent version in either Maven Local or Remote repository

I want to have gradle intelligently use the most recent SNAPSHOT for a given dependency which is available. 我想让gradle智能地使用最新的SNAPSHOT来获得可用的给定依赖项。

Assuming i have a build file like this: 假设我有一个这样的构建文件:

mavenCentral()
//    if (gradle.startParameter.refreshDependencies == false) {
    mavenLocal()
//   }
    maven {
      url "my_local_repo.com
   }
}

With a dependency listed like this: 使用如下列出的依赖项:

compile (group: 'com.mystuff', name: 'my-library', version: '1.0.0-SNAPSHOT', changing: 'true')

Which may exist both in Maven Local and in the Remote repo "my_local_repo.com" how do I ensure that Gradle always compiles with the most recent snapshot? Maven Local和Remote repo“my_local_repo.com”中可能存在哪些内容,如何确保Gradle始终使用最新的快照进行编译?

My reading here: 我在这里读到:

http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html

Specifically point 8.5: 具体点8.5:

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将按照指定的顺序在每个存储库中查找依赖项,并在包含所请求模块的第一个存储库中停止。

makes me believe that the mavneLocal version will always be preferred, however my reading of 让我相信mavneLocal版本将永远是首选,但我的阅读

51.7 here: 51.7这里:

http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories http://www.gradle.org/docs/current/userguide/dependency_management.html#sec:repositories

Given a required dependency, Gradle first attempts to resolve the module for that dependency. 给定必需的依赖项,Gradle首先尝试解析该依赖项的模块。 Each repository is inspected in order, searching first for a module descriptor file (POM or Ivy file) that indicates the presence of that module. 按顺序检查每个存储库,首先搜索指示该模块是否存在的模块描述符文件(POM或Ivy文件)。 If no module descriptor is found, Gradle will search for the presence of the primary module artifact file indicating that the module exists in the repository. 如果未找到模块描述符,Gradle将搜索是否存在主模块工件文件,指示该模块存在于存储库中。 ... Once each repository has been inspected for the module, Gradle will choose the 'best' one to use. ...一旦检查了每个存储库的模块,Gradle将选择要使用的“最佳”存储库。 This is done using the following criteria: 这是使用以下标准完成的:

and 51.2.4 和51.2.4

Alternatively, sometimes the module you request can change over time, even for the same version. 或者,有时您请求的模块可能会随着时间的推移而发生变化,即使是相同的版本。 An example of this type of changing module is a Maven SNAPSHOT module, which always points at the latest artifact published. 这种类型的更改模块的一个示例是Maven SNAPSHOT模块,它始终指向已发布的最新工件。 In other words, a standard Maven snapshot is a module that never stands still so to speak, it is a “changing module”. 换句话说,标准的Maven快照是一个永远不会停滞不前的模块,它是一个“改变模块”。

Muddies that substantially. 大致的泥泞。 It appears to say that all repo's are checked and the "best" choice is made (in this case presumably the most recent). 它似乎说所有的回购都被检查并且做出了“最佳”选择(在这种情况下可能是最新的)。

The bit I think you forgot to highlight from section 51.7 is this: 我认为你忘了在第51.7节中强调的一点是:

When the dependency is declared by a static version and a module descriptor file is found in a repository, there is no need to continue searching later repositories and the remainder of the process is short-circuited. 当依赖项由静态版本声明并且在存储库中找到模块描述符文件时,不需要继续搜索以后的存储库,并且该进程的其余部分被短路。

Which aligns with what is stated in section 8.5. 这与第8.5节中所述的内容一致。 But yes, for changing modules (ie. snapshots), Gradle will check every repo to find the latest artifact. 但是,是的,对于更改模块(即快照),Gradle将检查每个仓库以找到最新的工件。 For static modules, it will simply take the first one it finds. 对于静态模块,它只需要找到它找到的第一个。

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

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