【问题标题】:Having trouble with Gradle dependencies not updatingGradle 依赖项无法更新时遇到问题
【发布时间】:2019-11-19 18:11:49
【问题描述】:

我有一个项目,其中包含跨多个存储库共享的 3 个通用 jar。我正在使用 Intellij 2019.4。在我的 gradle 构建中,我包含了以下方法:

dependencyManagement {
    resolutionStrategy {
        // don't cache SNAPSHOT modules; always retrieve them from the maven cache
        cacheChangingModulesFor 0, 'seconds'
    }
}

这应该告诉 Gradle 不要缓存快照,但我的仍在缓存中。我构建并安装了一个常见的 jar,maven repo 有它,但 Gradle 缓存仍然有一个 24 小时前的 jar。我应该使用其他方法吗?我希望 Gradle 始终使用 .m2 存储库中的内容。

【问题讨论】:

  • 你确定过时的 jars 确实在构建中使用吗?我不认为 Gradle 在从本地存储库中获取工件时使用构建缓存。见docs.gradle.org/current/userguide/…
  • 是的,我确定。我对更新的 jar 所做的更改没有得到反映。当我导航到源代码时,它会将我带到 Gradle 缓存中的 jar。
  • 我有 same problem 并且在我发现之后,看起来 gradle 有某种延迟 ~1-5 分钟,即使您将 resolutionStrategy 设置为 0 秒

标签: gradle build.gradle


【解决方案1】:

Gradle 只会搜索 已声明 存储库中的模块。

这意味着,如果您需要一个库,SNAPSHOT,无论是否来自本地 Maven 存储库,您都需要在 Gradle 中将其声明为存储库。

repositories {
    mavenLocal() {
        content {
            includeModule("my.org", "someLib")
        }
    }
    // other repositories
}

但是,将mavenLocal() 添加到您的存储库中有caveats,因此请确保使用repository content filtering 仅在本地Maven 存储库中搜索那些SNAPSHOT 依赖项,如上所示。

【讨论】:

  • 也许我应该发布我的整个构建文件。我已经声明了mavenLocal()。还有什么我应该寻找的吗?
  • 请务必将您的存储库声明添加到您的问题中,并可能澄清您要获取的库的​​版本。最可能的解释是我展示的顺序,但可能还有其他原因。
【解决方案2】:

尝试将changing = true 添加到单个SNAPSHOT 依赖项的configClosure 中。

implementation("group:module:1.0-SNAPSHOT") {changing = true}

那么cacheChangingModulesFor 应该适用于他们:

configurations.all() {
    resolutionStrategy {
        cacheChangingModulesFor 0, "seconds"
    }
}

对于版本 latest.integration,这将需要将内部版本号添加到版本中 - 但是,这将保持构建可重复性,因为可以切换回库的先前版本。

还有一个 CLI 选项 --refresh-dependencies,可以刷新它们。

Gradle 手册也对此进行了解释:Declaring a changing version

在构建之前强制删除它们是另一种选择。

【讨论】:

    【解决方案3】:

    就我而言,使用changing = true 对我不起作用。但是配置缓存更改模块解决了我的问题。示例代码如下,添加build.gradle文件:

    configurations.all {
        // Don't cache changing modules at all.
        resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
    }
    

    见:https://docs.gradle.org/current/userguide/dependency_management.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-28
      • 1970-01-01
      • 2017-04-10
      • 1970-01-01
      • 2014-10-20
      • 1970-01-01
      • 2016-09-03
      • 2015-02-16
      相关资源
      最近更新 更多