Getting java version of current gradle run

Can anybody please help me how to run the below command in gradle:

gradle -version | grep ^JVM

Thanks, Sanjiv Note: This topic was created from a reply on the Need help to compile Java code in Gradle topic.

Can you give more background information what you try to achieve with the jvm version information? You can get Information about the current Jvm by using:

def currentJvm = org.gradle.internal.jvm.Jvm.current()
println currentJvm
1 Like

Hi Rene,

I am not looking for the JVM information. I need to extract the current Java and Gradle version to use somewhere in the script. I was trying the following command:

gradle -version | grep JVM

I have written my gradle task also to get the same. This is the code:

task extarctVersion {

new ByteArrayOutputStream().withStream { os ->

def result = exec {

executable = ‘gradle’

args = [’-version’,’|’,‘grep JVM’]

standardOutput = os


output = os.toString()



I seems that the command after pipe symbol is not working. Is there some way in Gradle to get the current Java and Gradle version?



Thanks Rene :slight_smile:

Yes the code which you sent is giving me the Java version. Is there something similar to get the Gradle version no?

Thanks, Sanjiv


you can use GradleVersion for that:

println GradleVersion.current().getVersion()
  // or even better
 println GradleVersion.current().toString()

cheers, René

1 Like

Thanks Rene for your quick response!!!

Yup its working fine now.