How to skip/disable plugin execution based on Java version?

For Add Error Prone · Issue #2054 · remkop/picocli · GitHub,

I need to skip running GitHub - tbroyer/gradle-errorprone-plugin: Gradle plugin to use the error-prone compiler for Java,

IFF the Java Version that the build is running on (which can vary, due to a “matrix” build) is < 11.

What’s the recommended / best way of doing this?

This in a build.gradle appears to do the trick:

buildscript {
    repositories {
        gradlePluginPortal()
    }

    dependencies {
        classpath "net.ltgt.gradle:gradle-errorprone-plugin:3.1.0"
    }
}

if (JavaVersion.current().isJava11Compatible()) {
        apply plugin: "net.ltgt.errorprone"

        dependencies {
            errorprone("com.google.errorprone:error_prone_core:2.23.0")
        }
    }