Is there a simple way to remove one dependency from the local gradle cache?

Works great, but for newer versions of gradle, use this instead:

task seekAndDestroy{
    doLast {
        configurations.findanddelete.each{ 
            println 'Deleting: '+ it
            delete it.parent
        }
    }
}

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{
    doLast {
        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