The Maven build task now simplifies SonarQube analysis
Last month we released the MSBuild tasks for SonarQube analysis, which make it easy to analyze a .NET project. Today we are pleased to announce an updated Maven task that makes it easy for Java developers using Maven to trigger a SonarQube analysis in Visual Studio Online (VSO), and – when Update 1 is available soon – in Team Foundation Server (TFS) 2015.
Using the Maven task with SonarQube
The following screenshot shows a new build definition I created, to which I added a Maven task. You can see the new section named SonarQube Analysis in the parameters for this task.
If I set the checkbox, the page updates to request a Service Endpoint, which specifies the URL of the SonarQube server and the credentials required to send analysis data to it.
For information about creating a Service Endpoint for SonarQube, see this post.
If you use a version of SonarQube server earlier than 5.2, you must also enter the database connection string and the credentials for the database. If you are using SonarQube 5.2 or above, this isn’t required.
Customizing the Maven build
When you configure an MSBuild SonarQube analysis task, you must provide the project name, the project key, and the version. You might be wondering why I don’t provide these details for a Maven task. The reason is that they are automatically added to the default Maven POM file for the task. You can see in the following screenshot that this file is specified when you add a Maven task to a build definition.
You can customize some features of the analysis by editing the POM **file passed to the task, or by passing parameters for the **Options setting. For example, you can pass values for the SQ-related options such as authentication. For more details, see Configuring the SonarQube Analysis on the SonarQube website.
Note that, if any of the Maven goals specified for the task should fail (for example, test failures), the SonarQube analysis will continue. This is different from the default behavior with MSBuild, where each step is decomposed.
In this post, you’ve seen how you can easily trigger a SonarQube analysis from the Maven task in Visual Studio Online and Team Foundation Server 2015 (from Update 1). You just need to define your SonarQube Service Endpoint once, and then reuse it for as many builds as you wish.
We look forward to hearing from you, especially if you work with Java. Would you find value in having the same feature for Graddle or Ant tasks? Please send us your feedback by asking a question on StackOverflow, or directly by reporting any bugs you find on the SonarQube Google Group. You can also submit suggestions (for example, for new features), on User Voice.