How to check java version when running gradle?

If you put the check very early in your build lifecycle (plain check in the beginning of your build.gradle file or in the apply method of a plugin) you shouldn’t see any tasks executed.

you can use JavaVersion enum for that which is part of the gradle api:

if(JavaVersion.current() != JavaVersion.VERSION_1_8){
    throw new GradleException("This build must be run with java 8")
}

Leave a Comment

tech