[RFF] SonarQube Scanner for Gradle 2.2 (improved Android support)

206 views
Skip to first unread message

Julien HENRY

unread,
Oct 11, 2016, 11:14:08 AM10/11/16
to SonarQube
Hi guys,

I would like to publish a new version of the Scanner for Android. This is a continuation of the effort to better support Android projects out of the box.
This version should properly configure sonar.sources, sonar.tests, sonar.java[.test].binaries/libraries for all possible type of tests (JVM, instrumentation tests, libraries, test modules, ...).

A 2.2-rc1 was published on Gradle plugin portal: https://plugins.gradle.org/plugin/org.sonarqube

There are still some missing features (like automatic configuration of various reports path) but that will probably come later. Feel free to test on your Android projects and report any issue.

Feedback period is open until Friday.

++

Julien


m...@thomaskeller.biz

unread,
Oct 13, 2016, 10:14:55 AM10/13/16
to SonarQube

Hi Julien!

Flavoured sources are now correctly found and added to the specific properties.

I'm not sure however how 

sonarqube {
  androidVariant = "xxxxx"
}

is supposed to work. If I add "prodCompat" there (in my sample project at https://github.com/tommyd3mdi/sonarqube-android-example), I still see 

"src/internal/java" in "\:app.sonar.sources", which I would not have expected. Also. "sonar.java.binaries" and "sonar.binaries" still point to "app/build/intermediates/classes/internalBleeding/debug".


(Side note: If I configure "androidVariant = 'bla'" the execution still happily succeeds, I'd have expected some configuration error.)



And this is another weirdness which I already experienced with 2.1 (so this is not specific to this RC, but was apparently a regression coming from 2.0.1 previously), but in my "main" project the sonarqube task fails because a compile dependency that was apparently set on the sonarqube task fails. Of course, the project is regularly buildable, but just fails to compile when the compilation step is executed through the sonarqube dependency. I could not reproduce this in the sonarqube-android-example project, so I'm not sure what's going on there.


The issue seems to be in the step :someLibraryModule:compileDebugJavaWithJavac - this has dependencies to another library module, but this module does not seem to be on the classpath, because it cannot find any class from it.


The issue also pops up if I clean beforehand, i.e. execute `./gradlew clean sonarqube`, but as I said, is not existant when I regularly assemble or even directly call `./gradlew :someLibraryModule:compileDebugJavaWithJavac`. Do you do any classpath mangling there...?


Thomas.

Julien HENRY

unread,
Oct 13, 2016, 12:20:51 PM10/13/16
to SonarQube, m...@thomaskeller.biz
Hi Thomas,


Le jeudi 13 octobre 2016 16:14:55 UTC+2, m...@thomaskeller.biz a écrit :

Flavoured sources are now correctly found and added to the specific properties.

I'm not sure however how 

sonarqube {
  androidVariant = "xxxxx"
}

is supposed to work. If I add "prodCompat" there (in my sample project at https://github.com/tommyd3mdi/sonarqube-android-example), I still see 

"src/internal/java" in "\:app.sonar.sources", which I would not have expected. Also. "sonar.java.binaries" and "sonar.binaries" still point to "app/build/intermediates/classes/internalBleeding/debug".


(Side note: If I configure "androidVariant = 'bla'" the execution still happily succeeds, I'd have expected some configuration error.)


This is expected to fail (and I have tested) so you may do something wrong. Do you set the variant on the app module or on the root project? Also the variant name should be 'prodCompatDebug'.

 

And this is another weirdness which I already experienced with 2.1 (so this is not specific to this RC, but was apparently a regression coming from 2.0.1 previously), but in my "main" project the sonarqube task fails because a compile dependency that was apparently set on the sonarqube task fails. Of course, the project is regularly buildable, but just fails to compile when the compilation step is executed through the sonarqube dependency. I could not reproduce this in the sonarqube-android-example project, so I'm not sure what's going on there.


The issue seems to be in the step :someLibraryModule:compileDebugJavaWithJavac - this has dependencies to another library module, but this module does not seem to be on the classpath, because it cannot find any class from it.


The issue also pops up if I clean beforehand, i.e. execute `./gradlew clean sonarqube`, but as I said, is not existant when I regularly assemble or even directly call `./gradlew :someLibraryModule:compileDebugJavaWithJavac`. Do you do any classpath mangling there...?


I am experimenting the same issue with your test project.

Running ./gradlew clean sonarqube after having defined the variant to 'prodCompatDebug' fails with a missing dependency between a class in androidTest and the main class under test.

The only "magic" I do is to dynamically add a dependency between task "sonarqube" and ["compile<variant>JavaWithJavac", "compile<variant>UnitTestJavaWithJavac" and "compile<variant>AndroidTestJavaWithJavac"]. This is to ensure all bytecode will be available when using sonarqube task. But this is maybe a problem to declare a dependency on those 3 tasks since there is no guaranty of the order. I'll investigate.

Julien HENRY

unread,
Oct 14, 2016, 11:38:46 AM10/14/16
to SonarQube, m...@thomaskeller.biz
Hi Thomas,

Would you mind testing with 2.2-rc2? I slightly cleaned up task dependencies. Not sure it will fix your issue, but at least in my case it did the trick.

++

Julien

Thomas Keller

unread,
Oct 16, 2016, 10:10:33 AM10/16/16
to Julien HENRY, SonarQube
Julien HENRY schrieb:
> Hi Thomas,
>
> Would you mind testing with 2.2-rc2? I slightly cleaned up task
> dependencies. Not sure it will fix your issue, but at least in my case
> it did the trick.

Yes, this did the trick! Awesome, thank you!

Thomas.

--
GPG-Key 0xCD45F2FD | Skype: realdeadfish | https://www.thomaskeller.biz
Please note that according to the EU law on data retention, information
on every electronic information exchange might be retained for a period
of six months or longer: http://www.vorratsdatenspeicherung.de/?lang=en


signature.asc

Thomas Keller

unread,
Oct 16, 2016, 10:14:51 AM10/16/16
to Julien HENRY, SonarQube

Hi Julien!

Julien HENRY schrieb:
>
> (Side note: If I configure "androidVariant = 'bla'" the execution
> still happily succeeds, I'd have expected some configuration error.)
>
>
> This is expected to fail (and I have tested) so you may do something
> wrong. Do you set the variant on the app module or on the root project?
> Also the variant name should be 'prodCompatDebug'.

I was sick and apparently that also meant mental sickness :) It works as
you have described, I just placed the sonarqube {} configuration not in
the app module, but in the root project and of course this could not work.

Thanks again for the awesome work!
signature.asc

Julien HENRY

unread,
Oct 17, 2016, 4:33:18 AM10/17/16
to SonarQube, julien...@sonarsource.com, m...@thomaskeller.biz
Thanks Thomas, I'll publish the final 2.2 release.
Reply all
Reply to author
Forward
0 new messages