Created
July 19, 2024 14:44
-
-
Save hsz/0fc45e1a6fc9ef73d4e4f5960058bded to your computer and use it in GitHub Desktop.
This scripts remove all IntelliJ Platform extracted copies from the Gradle Transformer Cache.
This file contains hidden or 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
@file:OptIn(ExperimentalPathApi::class) | |
import kotlin.io.path.* | |
/** | |
* This scripts remove all IntelliJ Platform extracted copies from the Gradle Transformer Cache. | |
*/ | |
fun main() { | |
val userHome = Path(System.getProperty("user.home")) | |
val caches = userHome.resolve(".gradle/caches") | |
val transforms = caches | |
.listDirectoryEntries("*") | |
.mapNotNull { entry -> entry.resolve("transforms").takeIf { it.exists() } } | |
.plus(listOfNotNull(caches.resolve("transforms-4").takeIf { it.exists() })) | |
val entries = transforms.flatMap { it.listDirectoryEntries() } | |
entries.forEach { entry -> | |
val container = entry | |
.resolve("transformed") | |
.takeIf { it.exists() } | |
?.listDirectoryEntries() | |
?.firstOrNull { it.isDirectory() } | |
?: return@forEach | |
val productInfoExists = container.resolve("product-info.json").exists() || | |
container.resolve("Resources/product-info.json").exists() | |
val buildExists = container.resolve("build.txt").exists() | |
val hasIdeaDirectory = container.startsWith("idea") | |
if (productInfoExists || buildExists || hasIdeaDirectory) { | |
println("DELETING: $container") | |
entry.deleteRecursively() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment