Skip to content

Instantly share code, notes, and snippets.

@granthenke
Created May 15, 2014 00:14
Show Gist options
  • Save granthenke/a6e67b53ce7f6f2c5943 to your computer and use it in GitHub Desktop.
Save granthenke/a6e67b53ce7f6f2c5943 to your computer and use it in GitHub Desktop.
Gradle task to invalidate the cache for a single passed dependency

Gradle Invalidate Task

Note: This is just a quickly hacked together task

To Use:

  • Paste the task below in a gradle build file
  • Call gradle invalidate -Pdependency=group:name:version substituting the dependency you want to invalidate.
task invalidate() {
doLast {
def depPath
if (project.hasProperty('dependency')) {
depPath = dependency.replace(':','/')
} else {
logger.error("Please pass a dependency to invalidate. Ex: gradle invalidate -Pdependency=group:name:version")
}
configurations.all.each { conf ->
conf.each { file ->
def path = file.getCanonicalPath()
if (path.contains(depPath) && file.exists()) { // Note: file could be listed multiple times
logger.warn("Removing from cache: {}", path)
file.delete()
}
}
}
}
}
@Baneeishaque
Copy link

In Module Level or Application level?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment