Running gradle tests with Java 11 for IntelliJ 2020.3 EAP
已回答
I'm trying to get my plugin (xquery-intellij-plugin) working with the IntelliJ 2020.3 EAP (203.3645-EAP-CANDIDATE-SNAPSHOT). My plugin uses gradle-intellij-plugin. I have made the necessary changes to build by plugin, and can run the plugin in IntelliJ 2020.3 using the runIde task.
When I try to run the check task I get an error that the class format (55 for Java 11) is not supported by the runtime (52 for Java 1.8). How do I make it so that the gradle build/runtime uses Java 11 for the test/check task? I have tried things like setting the source/targetCompatibility option., but haven't been able to make them work.
I have the following in my build.gradle file:
buildscript {
ext.java_from_build = { build ->
if (build >= 203) return "11"
return "1.8"
}
ext.idea_since_build = "203"
ext.java_version = ext.java_from_build(ext.idea_since_build.toInteger())
}
compileKotlin {
kotlinOptions { jvmTarget = java_version }
}
compileTestKotlin {
kotlinOptions { jvmTarget = java_version }
}
请先登录再写评论。
Reece, which Java version do you use for running the Gradle?
Do you mean which version is configured in the IDE? The Gradle JVM is set to "Project SDK", which is currently set to 1.8. Also, my JAVA_HOME is currently set to 1.8.
Try to run Gradle using Java 11.
That works, thanks.
So there is no way to configure this in gradle, like can be done with the Kotlin JDK target version? That would make it easier when switching between IntelliJ builds.
You can build the plugin against Java 8/11 target but it has to be done using Java 11 as a runtime.
I understand that I need to run against Java 11. What I would ideally like is something like:
javaHome = ext.java_home_from_idea_build(ext.idea_since_build.toInteger())
where javaHome configures what JDK the tests are run as (i.e. the check/test task), like how the runIde target uses the correct JBR so running IntelliJ 2020.3 works even though the Java version gradle is running is different.