Gradle and Lambda notations of Java 8

Hi,

My team has recently upgraded to Java 8. We have a file which uses Lambda notations of Java 8. Gradle fails to compile this file. Here’s what we have tried to fix:

  1. Check and make sure JAVA_HOME is set to java 1.8

  2. Check and make sure that gradle is using the correct version of java- gradle -version give the following
    Groovy: 2.3.10
    Ant: Apache Ant™ version 1.9.3 compiled on December 23 2013
    JVM: 1.8.0_60 (Oracle Corporation 25.60-b23)
    OS: Mac OS X 10.9.5 x86_64

  3. Tried to explicitly set java to 8 by setting
    compileJava.setSourceCompatibility(‘1.8’)
    compileJava.setTargetCompatibility(‘1.8’)

  4. tried to set org.gradle.java.home=’/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home’

It seems like the problem is with only one file. Searched the internet and didn’t find any information about this specific issue. Can anyone help me with this?

Thanks,
Deep

If you check the .class files that were created, are they version 52? You can check with file path/to/some.class

Are the compilation errors related to the lambda or missing dependencies or something else? Can you post them?

IntelliJ is complaining saying that it wasn’t able to resolve import java.util.function.Function dependency of Java 8

So it is basically a dependency issue.

Found a fix for the issue. It is not related to gradle, it is related to the installation of JDK 1.8.0_60

I checked that javac -version = 1.7
there are other people facing this issue.

I had to do

sudo rm -rf /Library/Java/Extensions

to fix it.

Thanks.

So was gradle -version reporting a 1.8 JVM?

Glad you got things working.