Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a minimal required Java update in Gradle?

Tags:

gradle

I'm building a Java FX application which uses the Dialog classes added to Oracle JDK 1.8 in update 40. Therefore, the minimal required Java version is 1.8u40.

I now want to ensure this version requirement in my Gradle build file. Obviously, checking against the major version with

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

does not help in this case as it omits the update number.

How do I specify this contraint in my build file?

like image 725
Skaldarnar Avatar asked Oct 31 '22 04:10

Skaldarnar


1 Answers

Taking into account Opal's suggestion the following splits the version string and checks against the update number.

if (javaVersion.startsWith("1.8.0") && javaVersion.split("_")[1].toInteger() < 40) {
    throw new GradleException("Java version 1.8.0_40 or later required, but was $javaVersion")
}
like image 50
Skaldarnar Avatar answered Nov 12 '22 08:11

Skaldarnar