How do I tell Gradle to use specific JDK version?

前端 未结 17 2177
时光取名叫无心
时光取名叫无心 2020-11-22 12:12

I can\'t figure out to get this working.

Scenario:

  • I have an application built with gradle
  • The application uses JavaFX

What I w

相关标签:
17条回答
  • 2020-11-22 12:22

    If you just want to set it once to run a specific command:

    JAVA_HOME=/usr/lib/jvm/java-11-oracle/ gw build
    
    0 讨论(0)
  • 2020-11-22 12:27

    So, I use IntelliJ for my Android project, and the following solved the issue in the IDE:

    just cause it might save someone the few hours I wasted... IntelliJ -> Preferences -> Build, Execution, Deployment -> Build tools -> Maven -> Gradle

    and set Gradle JVM to 1.8 make sure you also have JDK 8 installed...

    NOTE: the project was compiling just fine from the command line

    0 讨论(0)
  • 2020-11-22 12:28

    If you are using linux and gradle wrapper you can use following solution.

    Add path to local.properties file:

    javaHome=<path to JDK>
    

    Add to your gradlew script file:

    DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
    source $DIR/local.properties 2>/dev/null
    
    if ! [ -z "$javaHome" ]
    then
      JAVA_HOME=$javaHome
    fi
    

    In this solution, each developer can set his own JDK path. File local.properties shouldn't be included in version control system.

    0 讨论(0)
  • 2020-11-22 12:29

    there is a Gradle plugin that download/bootstraps a JDK automatically:

    https://plugins.gradle.org/plugin/com.github.rmee.jdk-bootstrap

    No IDE integration yet and a decent shell required on Windows.

    0 讨论(0)
  • 2020-11-22 12:29

    Android Studio

    File > Project Structure > SDK Location > JDK Location >

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

    GL

    Install JDK

    0 讨论(0)
  • 2020-11-22 12:30

    To people ending up here when searching for the Gradle equivalent of the Maven property maven.compiler.source (or <source>1.8</source>):

    In build.gradle you can achieve this with

    apply plugin: 'java'
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    

    See the Gradle documentation on this.

    0 讨论(0)
提交回复
热议问题