Last active
August 3, 2021 18:23
-
-
Save ghale/a7d8690ab0b824ee72ff845c4cef5802 to your computer and use it in GitHub Desktop.
Removing empty kapt output directory created at configuration time
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
gradle.taskGraph.whenReady { graph -> | |
graph.beforeTask { task -> | |
if (task instanceof org.jetbrains.kotlin.gradle.internal.KaptTask) { | |
if (task.destinationDir.exists()) { | |
if (task.destinationDir.listFiles().length == 0) { | |
logger.warn("Cleaning empty output directory at ${task.destinationDir}") | |
assert task.destinationDir.delete() | |
} else { | |
logger.warn("Not cleaning output directory at ${task.destinationDir} as it exists and is not empty. See the '${task.path}.destinationDir' custom value to see contents.") | |
captureOutputDirContents(task) | |
} | |
} else { | |
logger.warn("Not cleaning output directory at ${task.destinationDir} as it does not exist.") | |
} | |
} | |
} | |
} | |
def captureOutputDirContents(Task task) { | |
def contents = [] | |
rootProject.fileTree(task.destinationDir).visit { contents << it.relativePath } | |
rootProject.buildScan.value("${task.path}.destinationDir", contents.join("\n")) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment