Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gradle 无法更新渐变依赖项_Gradle_Build.gradle - Fatal编程技术网

Gradle 无法更新渐变依赖项

Gradle 无法更新渐变依赖项,gradle,build.gradle,Gradle,Build.gradle,我有一个在多个存储库中共享3个通用JAR的项目。我正在使用Intellij 2019.4。在我的gradle构建中,我包括以下方法: dependencyManagement { resolutionStrategy { // don't cache SNAPSHOT modules; always retrieve them from the maven cache cacheChangingModulesFor 0, 'seconds' } }

我有一个在多个存储库中共享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 repo中的内容。

Gradle将只搜索声明存储库中的模块

这意味着,如果您需要本地Maven存储库中的库,
SNAPSHOT
,则需要在Gradle中将其声明为存储库

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

但是,在将
mavenLocal()
添加到存储库中时会遇到一些问题,因此请确保使用仅搜索本地Maven repo中的那些
SNAPSHOT
依赖项,如上所示。

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

implementation("group:module:1.0-SNAPSHOT") {changing = true}
然后应适用于他们:

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

对于版本
latest.integration
,这需要在版本中添加版本号-但是,这将保持版本的可复制性,因为可以切换回库的以前版本

还有一个CLI选项--refresh dependencies,用于刷新所有依赖项

Gradle手册也对此进行了解释:


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

在我的情况下,使用
changing=true
对我不起作用。但配置缓存更改模块可以解决我的问题。下面的示例代码,外接程序
build.gradle
文件:

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

请参阅:

您确定在构建中实际使用了过时的jar吗?我不认为Gradle在从本地存储库获取工件时使用构建缓存。看,是的,我肯定。我对更新的jar所做的更改没有反映出来。当我导航到源代码时,它会将我带到Gradle缓存中的jar。我有一个jar,在我发现后,Gradle似乎有某种延迟~1-5分钟,即使您设置了resolutionStrategy 0秒。我应该发布我的整个构建文件。我已经声明了
mavenLocal()
。还有什么我应该寻找的吗?请在你的问题中添加你的存储库声明,并澄清你试图获取的库的版本。最可能的解释是,正如我所展示的那样,排序,但可能还有其他原因。