Running Sonar on iOS (Objective-C) Projects with Gradle

September 8, 2014 3 By Tad Reeves

After getting the basics out of the way on setting up Sonarqube on Mac OSX, one has to invoke it somehow.   We settled on building our iOS project with Gradle, and as such, are using the sonarRunner plugin for Gradle to fire up the Sonar analysis.

Making the Sonar Gradle Plugin Work

Getting the SonarQube plugin for Gradle to work was pretty straightforward.

In your build.gradle file, first insert:

Then, define Sonar properties for Objective-C analysis as follows:

This will then give you a target when invoking the Gradle wrapper of “sonarRunner”, such that you can just execute:

And this will go about downloading the needful dependencies to make the SonarQube plugin work, and will then insert the analysis data into Sonar.

Making GCov Test Coverage Reports Work

Now, the above analysis worked pretty trouble free for me.  However, as noted in the docs for the SonarSource Objective-C plugin, the plugin will not, out of the box, give you test coverage / code coverage reports.

You’ll first have to get the xcode project to generate the gcno/gcda code coverage reports as covered here.

Then, execute something like the following to get the gcov files generated from that:

That final line in the sonar properties is meant to then tell it where to look for the gcov reports:

EDIT:  Just found out that despite code coverage and ingest of gcov files being mentioned in their documentation, the C++/Objective-C plugin for SonarQube presently does not do code/test coverage reporting for Objective-C.  This is actively under development, meant to release in October 2014.