Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle / IntelliJ IDEA: sourceCompatibility revert to previous value in IDE settings

Setting sourceCompatibility and targetCompatibility to JavaVersion.VERSION_11 has not expected effect in my IntelliJ/Grade/Java project.

Even I set Project SDK and Project Language Level in Project Structure manually to 11, it reverted to 8 and 6 after I Refresh Gradle project (or Import Changes). See below image:

enter image description here


To ensure I created a new project and test these in it. This is its tree view:

enter image description here

The only build.gradle file:

plugins {
    id 'java'
}

group 'test'
version '1.0-SNAPSHOT'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Gradle version is 4.10.2 as you can see it in gradle-wrapper.properties file:

#Tue Nov 13 00:53:45 IRST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

And this is environment information:

IntelliJ IDEA 2018.1.5 (Community Edition)
Build #IC-181.5281.24, built on June 12, 2018
JRE: 1.8.0_152-release-1136-b39 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

This is an image from my SDKs:

enter image description here


Also, according to this answer, I made below configuration to build.gradle, but the problem persists:

group 'test'
version '1.0-SNAPSHOT'

allprojects {
    apply plugin: 'java'
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

repositories {
    ...

And also below configuration according to another answer on the same post:

group 'test'
version '1.0-SNAPSHOT'

allprojects {
    apply plugin: 'java'

    tasks.withType(JavaCompile) {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
}

repositories {
    ...
like image 227
Mir-Ismaili Avatar asked Nov 06 '22 23:11

Mir-Ismaili


1 Answers

For such issues compatibility of tools matter, you can upgrade your IDE version to a version >= 2018.2.

Quoting a JetBrains blog #Java11 in IntelliJ IDEA 2018.2

The next version of Java is due out in September, and IntelliJ IDEA 2018.2 is ready for it.

like image 137
Naman Avatar answered Nov 14 '22 00:11

Naman