SonarQube - Android not working for gradle 3.0.0

Viewed 6167

Android sonarqube worked until I updating android studio. Now it gives an error

FAILURE: Build failed with an exception.

* What went wrong:
com.android.build.gradle.api.ApkVariant.getCompileLibraries()Ljava/util/Collection;

I think this happens because gradle dependency syntax changed from 'compile' to 'implementation' like below in newest android version.

from

dependencies {
    compile ........
    compile ........
}

to

dependencies {
    implementation ........
    implementation ........
}

Can anyone please help me to configure sonarqube for new android version

5 Answers

Read the last part of the answer to get the latest updates

Original answer

I've performed some researches:

  • here you can find the issue tracked internally by SonarQube

  • here you can find the issue opened by a SonarQube developer asking Google about the API change. As stated by Google engineers this change is intended and an alternative API already exists. SonarQube stated they won't support android plugin 3.0.0 until the final release or at least RC version

Result:

To continue to work you are forced to build your project with the current stable Android Studio and Android plugin v2.X.X


UPDATE - 6th November 2017

SonarQube released the new version 2.6 which is fully compatible with the AGP (Android Gradle Plugin) 3.0.0.

buildscript {
    repositories {
        google()
        jcenter()

        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6.1"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

apply plugin: "org.sonarqube"

More info in the release page HERE

You can use my solution https://github.com/SonarSource/sonar-scanner-gradle/pull/33

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.0.0"
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6-rc1"
    }
}

apply plugin: 'org.sonarqube'

After sonarqube 2.6 was released just updating the plugin was enough for me

plugins {
    id "org.sonarqube" version "2.6"
}

Updating Benoit answer, the official sonar scanner gradle plugin (v2.6-rc1) already supports the new gradle syntax. So, update your root gradle script to:

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url "https://jitpack.io"
        }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.0.0"
        classpath "com.github.SonarSource:sonar-scanner-gradle:2.6-rc1"
    }
}

apply plugin: 'org.sonarqube'

Try to use lower version of gradle

Related