The Sonar plugin provides integration with Sonar,
a web-based platform for monitoring code quality. The plugin adds a sonar
task
to the project, which analyzes the project's source code and stores the results in Sonar's database.
The sonar
task is a standalone task that needs to be executed explicitly. By default,
it gets configured to analyze the Java code in the main source set. In a typical setup, the task would
be run once per day on a build server.
Only projects which have the Java plugin applied (possibly by way of another plugin) are affected by the
Sonar plugin. Other projects can still declare a task of type Sonar
and configure it manually.
At a minimum, the Sonar plugin has to be applied to the project.
Typically, it is also necessary to configure connection settings for the Sonar server and database.
Example 26.2. Configuring connection settings
build.gradle
sonar { serverUrl = "http://my.server.com" globalProperty "sonar.jdbc.url", "jdbc:mysql://my.server.com/sonar" globalProperty "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver" globalProperty "sonar.jdbc.username", "myusername" globalProperty "sonar.jdbc.password", "mypassword" }
For a complete documentation of all Sonar-specific configuration properties, see the Sonar documentation.
.The Sonar plugin adds the following tasks to the project.
Table 26.1. Sonar plugin - tasks
Task name | Depends on | Type | Description |
sonar |
- | Sonar |
Analyzes the project's source code and stores results in Sonar's database. |