Created
November 12, 2020 19:38
-
-
Save ghale/c7562c38ddb42fdf3276b122bf7c110a to your computer and use it in GitHub Desktop.
Workaround for commonSourceSet issue in kotlin compile tasks
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
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompileWithWorkers) { task -> | |
project.gradle.taskGraph.beforeTask { | |
if (task == it) { | |
// Get the 'commonSourceSet' property and make it accessible | |
def field = task.class.superclass.superclass.superclass.getDeclaredField('commonSourceSet') | |
field.setAccessible(true) | |
// Store the current value, and if the 'source' property contains everything in 'commonSourceSet', | |
// clear it out for the purposes of snapshotting (i.e. the directories are already tracked by a different | |
// input property) | |
def originalCommonSourceSet = field.get(task) | |
project.rootProject.buildScan.value "${task.path}.source", task.source.files.join("\n") | |
if (!originalCommonSourceSet.files.isEmpty() && task.source.files.containsAll(originalCommonSourceSet.files)) { | |
field.set(task, project.files()) | |
} else { | |
// If there is something in 'commonSourceSet' not in 'source' track it so we can troubleshoot | |
project.rootProject.buildScan.value "${task.path}.commonSourceSet", originalCommonSourceSet.files.join("\n") | |
} | |
// Right before the task executes (after snopshotting), set the property back to its original value | |
task.doFirst { | |
field.set(task, originalCommonSourceSet) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment