Gradle is not using correct Java Compiler

Hi, I am trying to migrate my Java project to Gradle. I previously compiled and built it with Eclipse. I have jdk7 and jdk8 installed, and my PATH and JAVA_HOME both point to my jdk8 installation.

When I attempt to build my application, I get syntax errors which seem as if Gradle is attempting to build the application with a Java version previous to 1.7. This is perfectly valid java 1.7+ syntax.

>gradlew.bat jar
...
.../classname.java:33: error: cannot infer type arguments for
HashSet<> Set<ZipEntry> entries = new HashSet<>(Collections.list(zipFile.entries()));

However, Gradle appears to have jdk 1.8 available.

>gradlew.bat -v
  ------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
  Build time:
 2014-09-08 10:40:39 UTC
Build number: none
Revision:
   e6cf70745ac11fa943e19294d19a2c527a669a53
  Groovy:
     2.3.6
Ant:
        Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:
        1.8.0_20 (Oracle Corporation 25.20-b23)
OS:
         Windows 8.1 6.3 amd64

I’m not sure what is wrong here. Can anyone help?

Hi Andrew Another source for the java home is the property org.gradle.java.home found in your %USERPROFILE%/gradle.properties file (see http://www.gradle.org/docs/current/userguide/build_environment.html)

Please check if this is set. Best regards

Kon

Hi Kon,

I didn’t have a gradle.properties file in my %USERPFOILE%. I tried creating one and inserting the path to my JDK Installation, but there was no change.

org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_20

or

org.gradle.java.home="C:\Program Files\Java\jdk1.8.0_20"

Andrew

Hi Kon,

I meandered across another of your answers, and the person had a similar problem to mine. What fixed my problem was adding this to build.gradle.

compileJava {
  sourceCompatibility = '1.7'
  targetCompatibility = '1.7'
}

from http://forums.gradle.org/gradle/topics/cant-build-java-1-8-even-with-proper-java-version-in-use