Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SonarQube - Android not working for gradle 3.0.0

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

like image 498
thinuwan Avatar asked Oct 02 '17 11:10

thinuwan


People also ask

How do I run Sonarqube with gradle?

login property in your command line or you configure it as part of your gradle. properties file. Execute gradle sonarqube -Dsonar. login=yourAuthenticationToken and wait until the build has completed, then open the web page indicated at the bottom of the console output.

How do I use Sonarqube on Android?

Access the running SonarQube instance, in my case, I'm running locally on port 9000, so I can just access it in http://localhost:9000,then login with admin as user and password. This assumes that you have already created an Android Studio project. We need to add the sonar scanner plugin and jacoco for the tests.


2 Answers

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'
like image 124
Benoit Avatar answered Oct 14 '22 14:10

Benoit


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

like image 36
MatPag Avatar answered Oct 14 '22 14:10

MatPag