Java – Execution failed for task ‘:compileJava’. > invalid source release: 1.7


I am using :

  1. gradle-2.3
  2. javac -version = 1.7
  3. jre = 1.7
  4. regedit shows it is pointing to 1.7.

But I am still getting below error

Execution failed for task ':compileJava'. > invalid source release: 1.7

Please let me know how to fix it.

Best Solution

You say you are running with Java 7, but are you really sure?

Because as far as I know that error occurs precisely when you are using a source / target level that is not supported by the JVM you are running gradle with. So if I were to take a guess I'd say that gradle seems to think your JDK doesn't support Java 7 (so its JDK 6 or lower)

Maybe double check that

a) Gradle itself is running with JDK 7. If you run gradle from within Eclipse using the STS gradle tooling, it will use the workspace default JRE to run gradle. Check that it is at least a JDK 7. (Go to "Windows >> Preferences >> Java >> Installed JRE". The JRE with a 'check mark' is the one Gradle will run with).

b) Gradle may accidentally pick up another JDK to compile stuff with if it finds an environment variable 'JAVA_HOME'. So double check that it isn't pointing to a JDK 6 or lower.