Trying to fail my Gradle build in case of critical or blocker warning

I’m trying to fail my Gradle build in case of critical or blocker warning reported by Sonar.

I have a buildscript section with sonar gradle plugin :

buildscript {
    dependencies {
        classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.3'
    }
}

I apply the sonarqube plugin among the other plugins:

apply plugin: 'java'
apply plugin: 'org.sonarqube'

I have a sonarqube section with properties :

sonarqube {
    properties {
        property 'sonar.host.url', 'http://some.host:8743'
        property 'sonar.projectKey', 'some-project'
        property 'sonar.login', '${env.SONAR_TOKEN}'
        property 'sonar.qualitygate.wait', 'true'
    }
}

I run sonarqube after unit tests :

tasks.withType(Test) {
    finalizedBy 'sonarqube'
}

And I have such issue :

org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0

My project must build on JDK8. Upgrading it to JDK11 is not an option (it’s a vendor constraint, we don’t get to choose the JDK to use).
What can I do to make my build work ?

SonarQube Community EditionVersion 9.8 (build 63668)
Gradle 2.3 and 5.6.4
JDK 8

Hey there.

Even if you build with JDK 8, you can still switch to Java 11 for analysis. Check out the documentation here on Scanner Environment.