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")
}