javagradlesonarqubegradle-pluginsonarqube-scan

Disable a gradle plugin depending on the java target


I'm using Gradle 3 and Sonarqube on a Java7 project: https://github.com/cbeust/testng/blob/master/build.gradle

And my ci is Travis with Java7 & Java8: https://travis-ci.org/cbeust/testng/

Only recent versions of the Sonarqube plugin support Gradle 3 and they only run on a Java8 runtime. When I run the Gradle build with Java7 then it fails with java.lang.UnsupportedClassVersionError: org/sonarqube/gradle/SonarQubePlugin : Unsupported major.minor version 52.0

I tried to enable the SonarQube plugin with Java8 only but it fails too: https://github.com/cbeust/testng/blob/update-gradle-plugins/build.gradle

I tried to define the SonarQube plugin in an external gradle file but Gradle allows the plugin definition in the main file only.

I'd like to avoid the duplication of the build.gradle. Is it possible?


Solution

  • Make the plugins DSL not auto-apply the plugin and apply it manually like

    plugins {
        id "org.sonarqube" version "2.2.1"
    }
    
    apply plugin: 'org.sonarqube'
    

    then you should be able to put the applying into a separate Gradle file, or only apply it depending on any condition you can formulate with Groovy.