Gradle – Different JDK Version for Source and Test


How can I configure Gradle to compile test classes for a different Java version than source classes?

I’m writing a project for Java 1.7, and I want to use Java 1.8 in my tests so I can use Lambda Behave. In Maven this is pretty straightforward, but I can’t see how to achieve the same result in Gradle.


Of course, immediately after posting the question I stumble across the answer!

apply plugin: "java"

compileJava {
    sourceCompatibility  1.7

compileTestJava {
    sourceCompatibility  1.8

Answered By – EngineerBetter_DJ

Leave a Comment