Build: Workaround java-rt loading into Gradle daemon

Fixes IDEA diff for tests not showing diff transfer buttons in the
 "Click to see difference" window for a failed test
This commit is contained in:
Vyacheslav Gerasimov
2021-12-21 22:48:45 +03:00
committed by teamcity
parent d7c7d1efd2
commit 03a3e7c68e
2 changed files with 24 additions and 0 deletions
+1
View File
@@ -114,6 +114,7 @@ rootProject.apply {
from(rootProject.file("gradle/checkCacheability.gradle.kts"))
from(rootProject.file("gradle/retryPublishing.gradle.kts"))
from(rootProject.file("gradle/modularizedTestConfigurations.gradle.kts"))
from(rootProject.file("gradle/ideaRtHack.gradle.kts"))
}
IdeVersionConfigurator.setCurrentIde(project)
+23
View File
@@ -0,0 +1,23 @@
// Remove this hack when IDEA-285445 (Gradle plugin doesn't handle java-rt from IDEA maven repo the same way as idea_rt.jar) is fixed
// https://github.com/JetBrains/intellij-community/blob/0e2aa4030ee763c9b0c828f0b5119f4cdcc66f35/plugins/gradle/java/resources/org/jetbrains/plugins/gradle/java/addTestListener.groovy#L11
if (isIdeaActive) {
gradle.taskGraph.whenReady {
allTasks.filterIsInstance<Test>().forEach { task ->
task.doFirst {
task.classpath.files.find { it.name.startsWith("java-rt") }?.let { javaRtJar ->
try {
val urlClassLoader =
Class.forName("org.gradle.launcher.daemon.bootstrap.DaemonMain").classLoader as? java.net.URLClassLoader
urlClassLoader?.let {
it::class.java.getMethod("addURL", java.net.URL::class.java)
.invoke(it, javaRtJar.toURI().toURL())
}
} catch (e: RuntimeException) {
logger.log(LogLevel.WARN, "Failed to load java-rt into Gradle daemon", e)
}
}
}
}
}
}