Created
July 13, 2017 14:59
-
-
Save corneil/6820676025b2d18fae7d1b03a73b75c5 to your computer and use it in GitHub Desktop.
Groovy script to remove 'unresolved' dependencies from local Maven Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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