android - Gradle:根据 Maven 本地或远程存储库中的最新版本解决 SNAPSHOT 依赖性

标签 android maven gradle

我想让 gradle 智能地为可用的给定依赖项使用最新的 SNAPSHOT。

假设我有一个这样的构建文件:

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

具有如下列出的依赖项:

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

它可能同时存在于 Maven 本地和远程存储库“my_local_repo.com”中,我如何确保 Gradle 始终使用最新的快照进行编译?

我在这里阅读:

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

特别是第 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.

让我相信 mavneLocal 版本将永远是首选,但是我对

的阅读

这里是 51.7:

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. Each repository is inspected in order, searching first for a module descriptor file (POM or Ivy file) that indicates the presence of that module. 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. ... Once each repository has been inspected for the module, Gradle will choose the 'best' one to use. This is done using the following criteria:

和 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. In other words, a standard Maven snapshot is a module that never stands still so to speak, it is a “changing module”.

大大混淆了。似乎说所有 repo 都经过检查并做出“最佳”选择(在这种情况下可能是最近的)。

最佳答案

我认为您忘记在第 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.

这与第 8.5 节中所述的一致。但是,是的,对于更改模块(即快照),Gradle 将检查每个 repo 以找到最新的 Artifact 。对于静态模块,它将简单地获取它找到的第一个。

关于android - Gradle:根据 Maven 本地或远程存储库中的最新版本解决 SNAPSHOT 依赖性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26875462/

相关文章:

android - 为什么 Flutter 只能以 super 用户身份运行?

android - 激励视频广告未加载

java - NoSuchMethodError : com. google.common.util.concurrent.MoreExecutors.directExecutor 在 Elasticsearch jar 上发生冲突

java - Maven: versions:update-parent 后跟 install 安装旧版本

gradle - java和travis-ci的问题,编码覆盖率和gradle

java - 运行失败 java.util.NoSuchElementException

android - Android应用程序的命名约定?

android - android 如何设置TableRow之间的边距

java - 无法导入带有 type 标签的 Maven 依赖项

android - 如何在Android的应用程序中使用某些具有相同属性名称的gradle库?