Gradle - Could not target platform: 'Java SE 8' using tool chain: 'JDK 7 (1.7)'

前端 未结 9 948
执笔经年
执笔经年 2020-12-12 19:57

I am trying to import Gradle project in Intellij Idea with local Gradle distrib and getting stacktrace with the following message: Could not target platform: \'Java SE

相关标签:
9条回答
  • 2020-12-12 20:24

    Since I had to compile some source with 7 compatibility, because of some legacy system and ran into the same problem. I found out that in the gradle configuration there where two options set to java 8

    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    

    switching these to 1.7 solved the problem for me, keeping JAVA_HOME pointing to the installed JDK-7

    sourceCompatibility = 1.7
    targetCompatibility = 1.7
    
    0 讨论(0)
  • 2020-12-12 20:25

    For IntelliJ 2019:

    Intellij IDEA -> Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM

    Select correct version.

    0 讨论(0)
  • 2020-12-12 20:26

    For IntelliJ 2019, JDK 13 and gRPC:

    Intellij IDEA -> Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM

    and Select correct version.

    you might also have to adding below line in your build.gradle dependencies

    compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
    
    0 讨论(0)
  • 2020-12-12 20:26

    you have to change the -> sourceCompatibility = '1.7' in build.Gradle

    0 讨论(0)
  • 2020-12-12 20:27

    Finally I imported my Gradle project. These are the steps:

    1. I switched from local Gradle distrib to Intellij Idea Gradle Wrapper (gradle-2.14).
    2. I pointed system variable JAVA_HOME to JDK 8 (it was 7th previously) as I had figured out by experiments that Gradle Wrapper could process the project with JDK 8 only.
    3. I deleted previously manually created file gradle.properties (with org.gradle.java.homevariable) in windows user .gradle directory as, I guessed, it didn't bring any additional value to Gradle.
    0 讨论(0)
  • 2020-12-12 20:40

    I had a very related issue but for higher Java versions:

    $ ./gradlew clean assemble
    
    ... <other normal Gradle output>
    
    Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'.
    

    I noticed that the task succeeded when running using InteliJ. Adding a file (same level as build.gradle) called .java-version solved my issue:

     # .java-version
     11.0.3
    
    0 讨论(0)
提交回复
热议问题