问题描述
本地gradle缓存存储maven / gradle依赖关系的副本。 涵盖了如何清除整个缓存,但不是单个包。
有没有简单的方法从本地gradle缓存中删除一个包?例如,在积极开发图书馆时,这会很有用。为了测试次要的库更改,我现在必须从文件系统清除整个高速缓存,以便不使用旧的高速缓存版本的库。
据我所知,也可以使用中描述的。我不希望更改gradle配置,因为大部分时间和大多数开发人员默认的缓存行为都很好。
所以这里有一个快速的脚本:
seekanddestroy .gradle
defaultTasks'seekAndDestroy'
repositories {//此部分*需要*相同到你build.gradle的仓库部分
jcenter()
}
配置{
findanddelete
}
依赖关系{
//添加您需要刷新的所有依赖项
findanddelete'org.apache.commons:commons-math3:3.2'
}
任务seekAndDestroy()< ;< {
configurations.findanddelete.each {
println'删除:'+ it
delete it.parent
}
}
您可以通过运行 gradle -b seekanddestroy.gradle
演示如何使用:
如果您的build.gradle如下所示:
apply plugin:'java'
存储库{
jcenter()
}
依赖关系{
compile'org.apache.commons:commons-math3:3.2'
}
第一次构建时,包含一个下载依赖项:
λgradle clean build | grep下载
下载https://jcenter.bintray.com/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar
第二次清理构建,使用缓存的依赖关系,因此不需要下载:
λgradle clean build | grep下载
现在执行seekanddestroy:
λgradle -b seekanddestroy.gradle -q
删除:.gradle \caches\modules-2\files-2.1\org.apache.commons\commons- math3 \3.2\ec2544ab27e110d2d431bdad7d538ed509b21e62\commons-math3-3.2.jar
下一个构建,下载依赖再次:
λgradle clean build | grep下载
下载https://jcenter.bintray.com/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar
The local gradle cache stores copies of maven/gradle dependencies. How to clear gradle cache? covers how to clear the whole cache, but not individual packages.
Is there a simple way to remove one package from the local gradle cache? This would be useful, for example, when actively developing a library. To test a minor library change, I currently have to clear the entire cache from the filesystem so an old cached version of the library is not used.
I understand it is also possible to use the gradle ResolutionStrategy described in How can I force gradle to redownload dependencies?. I would prefer not to change the gradle configuration because most of the time and for most developers, the default caching behavior is fine.
So here's a quick script I whipped up:
seekanddestroy.gradle
defaultTasks 'seekAndDestroy'
repositories{ //this section *needs* to be identical to the repositories section of your build.gradle
jcenter()
}
configurations{
findanddelete
}
dependencies{
//add any dependencies that you need refreshed
findanddelete 'org.apache.commons:commons-math3:3.2'
}
task seekAndDestroy()<<{
configurations.findanddelete.each{
println 'Deleting: '+ it
delete it.parent
}
}
You can invoke this script by running gradle -b seekanddestroy.gradle
Demo of how it works:if your build.gradle looks like this:
apply plugin:'java'
repositories{
jcenter()
}
dependencies{
compile 'org.apache.commons:commons-math3:3.2'
}
First time build, includes a download of the dependency:
λ gradle clean build | grep Download
Download https://jcenter.bintray.com/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar
Second clean build, uses cached dependency, so no download:
λ gradle clean build | grep Download
Now run seekanddestroy:
λ gradle -b seekanddestroy.gradle -q
Deleting: .gradle\caches\modules-2\files-2.1\org.apache.commons\commons-math3\3.2\ec2544ab27e110d2d431bdad7d538ed509b21e62\commons-math3-3.2.jar
Next build, downloads dependency again:
λ gradle clean build | grep Download
Download https://jcenter.bintray.com/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar
这篇关于有没有简单的方法从本地gradle缓存中删除一个依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!