Continuing from the Android and Continuous Integration note, we’d also like to hook up our metrics gathering tool (Sonar – http://www.sonarsource.org/) into our CI builds of our android applications on Hudson.
I continue to be impressed with the android tool compilation tool chain.
What this note does NOT cover ….
- Installing or configuring Sonar (see http://www.sonarsource.org/)
- How to create/configure a sonar pom.xml for an ant based project, See the following for information on how to do that:
- Sonar homepage covering Sonar “light mode” (specifically http://docs.codehaus.org/display/SONAR/Documentation for information on how to configure Sonar/maven for use on ant/Android based projects
Hudson and Sonar
- Add in a pom.xml file to your project with the required sonar bits
- The outputDirectory setting in your pom.xml file will be different from eclipse to ant builds. For Ant builds, it needs to be set to ‘bin/classes’, if you are running sonar on a directory structure that eclipse has created, it can be set to simple ‘bin’
- You will need to include dependency blocks for the android.jar file, and any Google specific bits (i.e. maps) that you are using in your project.
<dependency> <groupId>com.google.android</groupId> <artifactId>android</artifactId> <version>2.2</version> <scope>system</scope> <systemPath>/<your path>/android-sdk/platforms/android-8/android.jar</systemPath> </dependency>
- You also need to make sure that the sonar.dynamicAnalysis property is set to ‘reuseReports’
- Configure Hudson
- I’m going to continue using Hudson plugins for this note, it is equally possible/valid to configure Hudson to execute a windows/unix shell command which calls maven to execute the sonar:sonar target.
- Add the Hudson Sonar plugin (via the Manage Hudson > Manage Plugins page)
- Configure Hudson to know about your Sonar server (via Advanced section in the Sonar section of the Manage Hudson > Configure System page)
- This is basically providing the same information to Hudson that is provided in the maven settings.xml file
- Enable the Sonar option from the Post-build Actions section on a per project basis for each project you would like to run sonar on.
NOTE: The Sonar run can fail, but the overall build seems to still show as passed if the build activities themselves pass (IMHO, this is good, because your full build didn’t fail, just a post build step).