# Gradle is not using correct Java Compiler

**URL:** <https://discuss.gradle.org/t/gradle-is-not-using-correct-java-compiler/1794>\
**Category:** Old Forum Archive\
**Created:** [October 9, 2014, 2:36am UTC](https://discuss.gradle.org/t/gradle-is-not-using-correct-java-compiler/1794 "2014-10-09T02:36:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_O\_Hara](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/andrew_o_hara/32/454_2.png) [@Andrew\_O\_Hara](https://discuss.gradle.org/u/Andrew_O_Hara)\
**Post date:** [October 9, 2014, 2:36am UTC](https://discuss.gradle.org/t/gradle-is-not-using-correct-java-compiler/1794/1 "2014-10-09T02:36:00Z")

</div>

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.

```gradle
>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.

```gradle
>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?

---

<div class="post-metadata">

**Author:** ![kons](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/kons/32/19_2.png) [@kons](https://discuss.gradle.org/u/kons)\
**Post date:** [October 9, 2014, 12:39pm UTC](https://discuss.gradle.org/t/gradle-is-not-using-correct-java-compiler/1794/2 "2014-10-09T12:39:00Z")

</div>

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](http://www.gradle.org/docs/current/userguide/build_environment.html))

Please check if this is set. Best regards

Kon

---

<div class="post-metadata">

**Author:** ![Andrew\_O\_Hara](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/andrew_o_hara/32/454_2.png) [@Andrew\_O\_Hara](https://discuss.gradle.org/u/Andrew_O_Hara)\
**Post date:** [October 9, 2014, 1:54pm UTC](https://discuss.gradle.org/t/gradle-is-not-using-correct-java-compiler/1794/3 "2014-10-09T13:54:00Z")

</div>

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.

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

```

or

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

```

Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_O\_Hara](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/andrew_o_hara/32/454_2.png) [@Andrew\_O\_Hara](https://discuss.gradle.org/u/Andrew_O_Hara)\
**Post date:** [October 9, 2014, 2:07pm UTC](https://discuss.gradle.org/t/gradle-is-not-using-correct-java-compiler/1794/4 "2014-10-09T14:07:00Z")

</div>

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.

```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](http://forums.gradle.org/gradle/topics/cant-build-java-1-8-even-with-proper-java-version-in-use)
