我有一个项目,在多个存储库中共享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回购中的内容。
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}
则cacheChangingModulesFor
应适用于它们:
configurations.all() {
resolutionStrategy {
cacheChangingModulesFor 0, "seconds"
}
}
对于版本latest.integration
,这将需要在版本中添加内部版本号,但这将保持内部版本的可复制性,因为可以切换回库的上一个内部版本。
还有一个CLI选项--refresh-dependencies
,用于刷新所有选项。
Gradle手册也解释了这一点:宣布一个不断变化的版本。
另一种选择是在构建之前强制删除它们。