Sonarqube is used as a useful static code analysis tool in many projects. Android Nature is no exception. Share here how to configure Sonarqube in Gradle when using Android Studio.
The following are simply described using both public maven repositories and private maven repositories:
One, use a public maven repository:
This is relatively simple.
Open Gradle Sonarqube Plugin official website: https://plugins.gradle.org/plugin/org.sonarqube
You can see that there are two ways to integrate the Sonarqube plug-in, and you can choose the right way:
1: All Gradle plugin versions are available:
Buildscript { repositories { maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2" }}apply plugin: "Org.sonarqube"
2:gradle Plugin version 2.1 above applies:
Plugins { id "org.sonarqube" version "2.2"}
Second, use a private maven repository:
The 2nd method above is not available, because writing Gradle will think of it as core plugin, which is resolved by default to
https://plugins.gradle.org/api/gradle/2.14.1/plugin/use/org.sonarqube/2.2
We open this URL in the browser, we will find that it is a JSON:
{ "id": "org.sonarqube", "version": "2.2", "Implementation": { "Gav": " org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2 ", " repo ":" Https://plugins.gradle.org/m2 " }, "Implementationtype": "M2_jar", "Legacy": true}
found that it is in the https://plugins.gradle.org/m2 according to the "Org.sonarqube" this ID to find the appropriate plug-in, and we need to find a plugin in their own repository, obviously this is not appropriate.
Therefore, you can only use the 1th method above:
Add this paragraph to the module's build.gradle, plus the task:
Sonarqube { Properties {property ' sonar.sources ', ' src ' property ' sonar.java.binaries ', ' build/ Intermediates/classes "Property " Sonar.test.binaries "," build/intermediates/classes "... // Join the configuration you need }}
So when you're ready to configure your sonar host:
Systemprop.sonar.host.url=https://xxxx:9000/
Run:
Gradle Sonarqube
Wait a moment, and when the build successfully appears, you'll see the code on Sonar portal.
Gradle configuration in Android Studio sonarqube