Skip to content

Instantly share code, notes, and snippets.

@corneil
Created July 13, 2017 14:59
Show Gist options
  • Save corneil/6820676025b2d18fae7d1b03a73b75c5 to your computer and use it in GitHub Desktop.
Save corneil/6820676025b2d18fae7d1b03a73b75c5 to your computer and use it in GitHub Desktop.
Groovy script to remove 'unresolved' dependencies from local Maven Repository
import groovy.io.FileType
def showOnly = true
def repoHome = new File(System.getProperty('user.home'), '.m2/repository')
def searchFolders = []
args.each { arg ->
if(arg == '-s') {
showOnly = true
} else if(arg == '-d') {
showOnly = false
} else {
searchFolders << new File(arg)
}
}
if(searchFolders.empty) {
searchFolders << repoHome
}
def toDel = new HashSet()
searchFolders.each { folder ->
println "Searching $folder"
folder.eachFileRecurse(FileType.FILES) { file ->
if(file.name.endsWith('pom.lastUpdated')) {
def pom = new File(file.parent, file.name - '.lastUpdated')
if(!pom.exists()) {
toDel << file.parentFile
}
}
}
}
toDel.each { dir ->
if(showOnly) {
println "For deletion:$dir.path"
} else {
dir.eachFileRecurse(FileType.FILES) { file ->
println "Deleting:$file.path"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment