Setting sourceCompatibility
and targetCompatibility
to JavaVersion.VERSION_11
has no expected effect on my IntelliJ/Grade/Java project.
Even though 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:
To ensure I created a new project and test these in it. This is its tree view:
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:
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 {
...
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.