这是我编写的一个快速脚本:
查找并销毁.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{
doLast {
configurations.findanddelete.each{
println 'Deleting: '+ it
delete it.parent
}
}
}
您可以通过运行来调用此脚本gradle -b seekanddestroy.gradle
其工作原理演示:
如果你的 build.gradle 看起来像这样:
apply plugin:'java'
repositories{
jcenter()
}
dependencies{
compile 'org.apache.commons:commons-math3:3.2'
}
首次构建,包括依赖项的下载:
λ gradle clean build | grep Download
Download https://jcenter.bintray.com/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar
第二次干净的构建,使用缓存的依赖项,因此无需下载:
λ gradle clean build | grep Download
现在运行eekanddestroy:
λ 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
下次构建,再次下载依赖项:
λ gradle clean build | grep Download
Download https://jcenter.bintray.com/org/apache/commons/commons-math3/3.2/commons-math3-3.2.jar