How to check which installed JDK used during Gradle build process

痞子三分冷 提交于 2019-12-02 12:29:55

You can add a task that prints what you need when executed (Kotlin DSL):

tasks {
    val j by creating {
        doLast {
            println(System.getProperty("java.home"))
        }
    }
}

Groovy DSL:

tasks.register("j") {
    doLast {
        println System.getProperty("java.home")           
    }
}

Then executing ./gradlew j:

/usr/lib/jvm/java-8-openjdk/jre

Why could gradlew use another JVM? Take a look at this script and you'll see that it uses JAVA_HOME variable to search for JVM. So probably the version from your PATH is not the same, that JAVA_HOME is pointing to.

I find an alternative way (except @madhead answer) just for when you use a Gradle daemon:

First, find PID of daemon by running gradlew --status (see here for more information). Sample output:

   PID STATUS   INFO
 11432 IDLE     5.0

Only Daemons for the current Gradle version are displayed. See https://docs.gradle.org/5.0/userguide/gradle_daemon.html#sec:status

Then use PID to find which JDK is used:

ll /proc/<PID>/exe

Sample output:

lrwxrwxrwx. 1 0xy 0xy 0 Jan  5 04:03 /proc/11432/exe -> /usr/local/jdk-11.0.1/bin/java

On Windows:

> wmic process where "processId=<PID>" get Name, ProcessID, ExecutablePath

Sample output:

ExecutablePath                                     Name      ProcessId
C:\Program Files\Java\openjdk-11.0.1\bin\java.exe  java.exe  11432 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!