gradle java9 Could not target platform: 'Java SE 9' using tool chain: 'JDK 8 (1.8)'

后端 未结 10 845
傲寒
傲寒 2020-12-11 14:39

I want to use java9 on my gradle project inside eclipse oxygen. When I run:

Run as> Gradle Test on  GreeterTest.java

with the followin

相关标签:
10条回答
  • 2020-12-11 15:02

    I had a similar issue with eclipse, I had to set JAVA_HOME in Properties -> Gradle.

    0 讨论(0)
  • 2020-12-11 15:06

    You should probably try to update your JAVA_HOME in system variables and Java version used in eclipse to be consistent to

    JAVA_HOME=/path/to/jdk9
    

    In MacOSX, something like :

    JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin
    

    As informed in comments, the default path on Linux would be :

    /usr/lib/jvm/java-9-openjdk
    
    0 讨论(0)
  • 2020-12-11 15:06

    For me the problem was that I used

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_10
        targetCompatibility JavaVersion.VERSION_1_10
    }
    

    but the project was configured for Java 1.8. So I changed these to 1_8 and it works.

    0 讨论(0)
  • 2020-12-11 15:09

    I faced the issue because in IntelliJ Idea in the Settings > Build Tools > Gradle In "Gradle" section, Gradlje JVM used an incorrect Java version. So I specify to use JAVA_HOME and it fixes the issue.

    0 讨论(0)
  • 2020-12-11 15:11

    From what I can see, it is the Gradle version issue. (Gradle and Java 9 compatibility issue).

    You need to upgrade the wrapper to 4.3.1, cli ref:

    # upgrade Gradle to 4.3.1 
    gradle wrapper --gradle-version 4.3.1 # not ./gradlew
    

    Let me know if that works.

    0 讨论(0)
  • 2020-12-11 15:14

    What I did to fix this problem was I did this on my imported project build.gradle on compileJava section I changed sourceCompatibility and targetCompatibility into 8. It works for me. this happen when you import project from other resource, which is build in different version.

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