清理gradle缓存,有没有简单的方法从本地gradle缓存中删除一个依赖项?

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值