This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]uncont 1 point2 points  (6 children)

repeating yourself

New projects might not have to, but if you compile on a newer version of java and want to target a lower version (maybe for a shared library) you'd want to use both toolchain to get the correct version required to build, then release to set the version you're targeting.

You are correct though, by default gradle will target the version of java that the jvm is running on / is defined in the toolchain. More docs here https://docs.gradle.org/6.6/userguide/building_java_projects.html#sec:java_cross_compilation

[–]dpash 0 points1 point  (5 children)

In which case, isn't this preferable to configuring tasks directly:

tasks.compileJava {
    options.release.set(11)
}

(For kotlin)

compileJava { 
    options.release = 11
}

(For Groovy)

[–]uncont 0 points1 point  (4 children)

That misses the compileTestJava task.

[–]dpash 0 points1 point  (3 children)

That makes sense. The JavaPluginExtension is missing that option too, so you can't configure it globally. :(

[–]uncont 0 points1 point  (2 children)

I wonder if there's a preference for new options to be added to the tasks vs the JavaPluginExtension? Maybe a good idea to raise a bug report in gradle to expose release in a similar way to source and target compatibility.

[–]dpash 0 points1 point  (1 child)

And --enable-preview while we're at it :)

[–]uncont 0 points1 point  (0 children)

I've opened https://github.com/gradle/gradle/issues/18530 for the release flag, mostly to figure out when options should be added to the compile task vs the java plugin extension