Skip to content

Instantly share code, notes, and snippets.

@sam43
Forked from granthenke/README.md
Created March 9, 2023 02:28
Show Gist options
  • Save sam43/f3b5bff093ddd60ab32aa78bec3d60d8 to your computer and use it in GitHub Desktop.
Save sam43/f3b5bff093ddd60ab32aa78bec3d60d8 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()
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment