[Gradle] Fix init script for coroutines

Use doFirst instead of beforeTask to add javaagent args for coroutines debugging.
This commit is contained in:
Ivan Gavrilovic
2021-04-09 15:16:19 +01:00
committed by Alexander Likhachev
parent 2bb7f6a168
commit 11b92bc597
@@ -27,16 +27,20 @@ class KotlinGradleCoroutineDebugProjectResolver : AbstractProjectResolverExtensi
val script =
//language=Gradle
"""
gradle.taskGraph.beforeTask { Task task ->
if (task instanceof Test || task instanceof JavaExec) {
def kotlinxCoroutinesCoreJar = task.classpath.find { it.name.startsWith("kotlinx-coroutines-core") }
if (kotlinxCoroutinesCoreJar) {
def results = (kotlinxCoroutinesCoreJar.getName() =~ /kotlinx-coroutines-core(\-jvm)?-(\d[\w\.\-]+)\.jar${'$'}/).findAll()
if (results) {
def version = results.first()[2]
def referenceVersion = org.gradle.util.VersionNumber.parse('1.3.7-255')
if (org.gradle.util.VersionNumber.parse(version) > referenceVersion) {
task.jvmArgs ("-javaagent:${'$'}{kotlinxCoroutinesCoreJar?.absolutePath}", "-ea")
gradle.taskGraph.whenReady { TaskExecutionGraph taskGraph ->
taskGraph.allTasks.each { Task task ->
if (task instanceof Test || task instanceof JavaExec) {
task.doFirst { Task forkedTask ->
def kotlinxCoroutinesCoreJar = forkedTask.classpath.find { it.name.startsWith("kotlinx-coroutines-core") }
if (kotlinxCoroutinesCoreJar) {
def results = (kotlinxCoroutinesCoreJar.getName() =~ /kotlinx-coroutines-core(\-jvm)?-(\d[\w\.\-]+)\.jar${'$'}/).findAll()
if (results) {
def version = results.first()[2]
def referenceVersion = org.gradle.util.VersionNumber.parse('1.3.7-255')
if (org.gradle.util.VersionNumber.parse(version) > referenceVersion) {
forkedTask.jvmArgs ("-javaagent:${'$'}{kotlinxCoroutinesCoreJar?.absolutePath}", "-ea")
}
}
}
}
}