54

I really got an 'overflow' trying to make these things to work together. I followed instruction from here: http://docs.sonarqube.org/display/PLUG/Android+Lint+Plugin and finally got a SonarQube 5.1.1 server with Android Lint plugin 1.1 installed. Then I configured my multi-module Gradle build to work with SonarQube plugin: see code fragment from root config below.

plugins {
    id 'org.sonarqube' version '1.0'
}

sonarqube {
    properties {

        property 'sonar.host.url', 'sonarqube-server:9000'
        property 'sonar.jdbc.url', 'jdbc:mysql://sonarqube-db:3306/sonar?useUnicode=true&characterEncoding=utf8'
        property 'sonar.jdbc.driverClassName', 'com.mysql.jdbc.Driver'
        property 'sonar.jdbc.username', 'sonar'
        property 'sonar.jdbc.password', 'sonar'
        property 'sonar.sourceEncoding', 'UTF-8'
        property 'sonar.login', 'admin'
        property 'sonar.password', 'admin'

        property 'sonar.profile', 'Android Lint'

        property 'sonar.import_unknown_files', true
        property 'sonar.android.lint.report', 'build/outputs/lint-results.xml'
    }
}

And after that I ran lint sonarqubetask to execute the analysis. As a result I got a bulk of Lint errors regarding 'retrolambda' project (java.lang.UnsupportedOperationException: Unknown ASTNode child: LambdaExpression), which is quite normal, and lint-results.xml (accompanied with HTML version) files per each module containing descriptions of issues discovered. The report said that there were 8 errors and 434 warnings found. But things went wrong when sonarqube plugin tried to upload the results to SonarQube server. The log was full of 'Unable to find file' and 'Unable to find rule' messages. And when the processing was over, then there were no issues reported for my project on SonarQube server.

And I am wondering, what did went wrong? I checked the paths, and all files were there. I looked through all discussions I could reach, and it seems like my config is correct and I do everything right. Does anybody have any clue, what I missed and what needs to be checked? Any suggestions or ideas are welcome.

I will be also happy if there is a way to import lint data using external SonarQube Runner, since this tool seems to be more predictable and stable then a Gradle plugin.

sviklim
  • 1,054
  • 1
  • 15
  • 30
  • Do the paths in the lint report appear to be correct? Are they relative or absolute? Does the analysis of a single module succeed? FYI, here are the docs for configuring a multi-module project for Sonar Runner analysis: http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Runner#AnalyzingwithSonarQubeRunner-Multi-moduleProject – G. Ann - SonarSource Team Aug 14 '15 at 18:16
  • 1
    Would you be able to share the error message you mention about Unable to find file /rule ? Might help to pinpoint the problem. As of your idea about using sonar-runner to import lint reports : this should work if you configure the `sonar.android.lint.report` property for sonar-runner. – benzonico Sep 05 '15 at 09:48

2 Answers2

8

I had success with a multimodule android project. Since the complete build files take too much space I show the relevant parts here only.

In the parent project's build.gradle I set:

buildscript {
    ...
    dependencies { classpath 'com.android.tools.build:gradle:1.5.0'
    ...
}
plugins { id "org.sonarqube" version "1.1" }

In the app project (and any other children) I set:

sonarqube {
    properties {
        property "sonar.profile", "Android Lint"
        property "sonar.sources", "./src/main/java"
    }
}

That was the minimum setup for SonarQube plugin to start analyzing the projects.

JJD
  • 50,076
  • 60
  • 203
  • 339
JanPl
  • 794
  • 6
  • 19
  • 1
    Wow, that really works. I was long looking for a solution, that made my day. AndroidStudio though still complains about the sonarqube 'properties' cannot be applied to groovy.lang.Closure ... wtf – Fred Felsbruckner Nov 25 '15 at 00:18
  • 2
    The sonar.profile property has been removed and must now be set through the Sonarqube UI: https://jira.sonarsource.com/browse/SONAR-5370 – Simon Raes Apr 08 '17 at 15:45
1

Your gradle settings seems fine, have you installed Android plugin on SonarQube server.

I don't see that step on your question, if not goto Settings->System->Update Center and install Android plugin.

enter image description here

Once that is installed you need to restart your SonarQube server and rerun sonar-runner.

Abhishek Patidar
  • 1,557
  • 1
  • 16
  • 25
  • * What went wrong: Execution failed for task ':app:compileDebugJavaWithJavac'. > javax/xml/bind/JAXBException I am gettin gthis error while running gradlew sonarqube. – Akshay Apr 09 '20 at 06:34