Skip to content

Instantly share code, notes, and snippets.

@hsz
Created July 19, 2024 14:44
Show Gist options
  • Save hsz/0fc45e1a6fc9ef73d4e4f5960058bded to your computer and use it in GitHub Desktop.
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.
@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