gpt4 book ai didi

linux - 如何删除 Jenkins Maven 本地存储库中的旧 Artifact

转载 作者:太空宇宙 更新时间:2023-11-04 10:47:16 27 4
gpt4 key购买 nike

我有一个 .m2/repository 目录,里面有很多旧 Artifact 。有没有办法用脚本或任何插件清理 .m2/repository 文件夹。

我还想告诉您,我想删除超过 14 天的 Artifact 。 .m2/repository 文件夹没有子文件夹。

任何潜在客户都将受到高度重视

最佳答案

这样的事情就是你的答案:

now = new Date()
configuration = new Configuration()
cleanedSize = 0
details = []
directoryFilter = new DirectoryFilter()
nonSnapshotDirectoryFilter = new NonSnapshotDirectoryFilter()

def class Configuration {
def homeFolder = System.getProperty("user.home")
def path = homeFolder + "/.m2/repository"
def dryRun = true
def printDetails = true
def maxAgeSnapshotsInDays = 60
def maxAgeInDays = 14
def versionsToKeep = ["3.1.0.M1"]
def snapshotsOnly = true
}


private def cleanMavenRepository(File file) {
def lastModified = new Date(file.lastModified());
def ageInDays = now - lastModified;
def directories = file.listFiles(directoryFilter);

if (directories.length > 0) {
directories.each {
cleanMavenRepository(it);
}
} else {
if (ageInDays > configuration.maxAgeSnapshotsInDays && file.canonicalPath.endsWith("-SNAPSHOT")) {
int size = removeDirAndReturnFreedKBytes(file)
details.add("About to remove directory $file.canonicalPath with total size $size and $ageInDays days old");
} else if (ageInDays > configuration.maxAgeInDays && !file.canonicalPath.endsWith("-SNAPSHOT") && !configuration.snapshotsOnly) {
String highest = obtainHighestVersionOfArtifact(file)
if (file.name != highest && !configuration.versionsToKeep.contains(file.name)) {
int size = removeDirAndReturnFreedKBytes(file)
details.add("About to remove directory $file.canonicalPath with total size $size and $ageInDays days old and not highest version $highest");
}
}
}
}

关于linux - 如何删除 Jenkins Maven 本地存储库中的旧 Artifact ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32625652/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com