Java Toolchain - print version

Love java toolchain and what it provides. Here’s how I’m using it:

// JDK version
java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(findProperty('javaLanguageVersion') ?: '8'))

I have this defined in a plugin that I use in all my projects. I have a default version as a fall-back, but allow projects to specify their desired version.

The question I have is there a way for me to print out the “active” in-use version when running my build? I am hoping that this piece could also be included in my plugin so that I don’t have to replicate it within all my projects.

Ah ha!

Here’s how I think I can solve this:

task displayJavaVersion {
    doLast {
        println "JDK version: ${java.toolchain.languageVersion.get().toString()}"

build.dependsOn displayJavaVersion

I can add this task to my plugin for as-needed execution and include it in the build chain like I have.

1 Like