Quantcast
Channel: Gradle Forums - Latest posts
Viewing all articles
Browse latest Browse all 20348

Eclipse running with JDK 11 -> Gradle 6.2.1 fails to compile source for JDK 8

$
0
0

I’m somewhat sure now that I’m not doing something wrong, but I simply misunderstood things: The problem is that my project gets build with JDK 11 in Eclipse and some packages have simply been removed from that JDK. Neither the source- nor target compatibility of Gradle can change that, they only influence the generated byte code in case compiling succeeds:

Buildship updates the compiler properties as follows:

  • Eclipse’s compiler compliance level and source compatibility is updated to Gradle’ sourceCompatibility
  • Eclipse’s generated .class file compatibility is updated to Gradle’s targetCompatibility .

But to make the build succeed using JDK 11, the missing packages need to be made available as additional dependency. To do so, I decided to create a new Gradle-file documenting that problem with the following code:

if (JavaVersion.current().isJava8())
{
	return
}

dependencies
{
	compileOnly 'javax.annotation:javax.annotation-api:1.3.2'
}

This can then be applied to build.gradle using the following line:

apply from:		'buildSrc/src/main/java/BuildByJdk11Workarounds.gradle'

So, when build with JDK 11, additional dependencies are simply made available and compiling succeeds again. The important thing in my setup is that I want to keep targeting JDK 8, that’s while the dependency is compileOnly and why my compatibility-options still look like the following:

java
{
	sourceCompatibility = JavaVersion.VERSION_1_8
	targetCompatibility = JavaVersion.VERSION_1_8
}

In theory, with JDK 11 those could be easier set using the newly introduced release-option. But I currently don’t know about the influence at development time, like the settings done in Eclipse.

tasks.withType<JavaCompile> {
	options.compilerArgs.addAll(['--release', '11')]
}

What might be of additional interest is planned support for toolchains, which sounds pretty mich like what Maven already has. Not sure, though, how that would work in the context of Eclipse, in which the JVM used by Eclipse itself is reused by Gradle by default.


Viewing all articles
Browse latest Browse all 20348

Trending Articles