2

I have a Gradle project that consists of an Android library module and a plain old Java module. (The Android library module has a dependency on the plain Java module.)

In the build.gradle file of the Android library module I have this:

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

And in the build.gradle file of the plain old Java module I have this:

compileJava {
    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"
}

When I hit the Gradle refresh button in IntelliJ IDEA 15, the language level for the Android module is set to Java 8 (as I'd expect) but the language level of the Java module is set to Java 1.6. Why is this and is there any way for IntelliJ to set the language level of the Java module to Java 8 on a refresh instead?

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147

1 Answers1

2

You can only use JavaVersion.VERSION_1_8 if you are using the new Jack compiler or the Retrolambda plugin for Gradle.

So you should be using:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

As far as the Intellij/Android Studio language settings goes:

  1. File -> Project Structure:

enter image description here

  1. You should set the project language settings accordingly:

enter image description here

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • Thanks for the pointer on dropping the Java version for the Android module down to `1.7`. (I thought I could compile with Java 1.8 as long as I didn't use the Java 1.8 language features.) I dropped the Java version in the plain old Java module to `1.7` also and now IntelliJ sets the `Project Language Level` to `8` and the `Language level` of both modules in the project to `7` automatically every time I do a fresh. Strange why the project level and module level values are different but it works for me so I'll leave it be for now. – Adil Hussain Apr 18 '16 at 14:46