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
.../ 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
        Apache Ant(TM) version 1.9.3 compiled on December 23 2013
        1.8.0_20 (Oracle Corporation 25.20-b23)
         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 found in your %USERPROFILE%/ file (see

Please check if this is set. Best regards


Hi Kon,

I didn’t have a file in my %USERPFOILE%. I tried creating one and inserting the path to my JDK Installation, but there was no change.\Program Files\Java\jdk1.8.0_20

or"C:\Program Files\Java\jdk1.8.0_20"


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'