Is there an built-in or elegant way to require a minimum JVM version for running a build script?

I would like to be able to define a minimum JVM version for the Gradle buildscript (build.gradle) itself. Is there an built-in or elegant way to do this?

This issue came up while trying to build Terasology on a JDK 6 system:

The best solution I can come up with is:

if (!org.gradle.api.JavaVersion.current().isJava7Compatible()) {

// The build script (this file) requires Java 7+, throw error if not present

throw new GradleScriptException(“Build script requires Java 7”, null)


It would be nice if there were a buildScriptCompatibility property that is set to a JavaVersion. Is there something like that?

I use,

assert['java.specification.version'] == '1.7'

Assert displays a nice error message automatically.

Yeah, Andrew is right. I want Java7 or later, not exactly Java 7. Looks like that’s what I’m going to submit in a pull request for Terasology.

I’m thinking about opening an enhancement issue for Gradle asking for a project property for defining a JavaVersion for the buildscript itself, something like:

buildScriptCompatibility = 1.7

// Java version required to run the buildscript


Looks like I can’t submit Jira issues, so I created a problem report on this forum that will hopefully convince someone to open one:

Combination of both of your ideas to get the one liner and the compatible vs exact version:

assert org.gradle.api.JavaVersion.current().isJava7Compatible()