Q:

How to tell gradle jdk must be 1.8 without setting a JAVA_HOME like ant

I read this post
How do I tell Gradle to use specific JDK version?
which seems to miss the point.  Developers should be responsible for setting their own JAVA_HOME to where they installed it which is different on different OS.
What I would like is to set which jdk major version should be in use like 1.8 so it fails if their JAVA_HOME is pointing to 1.7 with a nice error message saying please fix your JAVA_HOME variable.
Is this possible in gradle?
The important part is to have something in my git repo that says gradle.jdk.must.be=1.8  and if using JAVA_HOME OR using gradle.properties from their home directory or whatever, it tries to compile using JAVA_HOME and if it fails, it should tell them nicely to setup JAVA_HOME or gradle.properties or whatever.
Related post: How to set JDK version in Gradle project WITHOUT explicit JDK path?
The point being when someone checks out a project, it is sort of confusing when it just doesn't compile and they don't know why with no error telling them what to fix.
thanks,
Dean

A:

task checkJavaVersion << {
    if (!JavaVersion.current().isJava8()) {
        String message = "ERROR: Java 1.8 required but " +
                         JavaVersion.current() + 
                         " found. Change your JAVA_HOME environment variable.";
        throw new IllegalStateException(message);
    }
}

compileJava.dependsOn checkJavaVersion

