How to Integrate SonarQube into a Multi‑Module Spring Boot Project with Gradle 3.3
This guide shows how to configure a Spring Boot multi‑module project using Gradle 3.3 to run SonarQube 5.6.6 analysis by adding the SonarQube plugin, setting repository and classpath, defining sonar properties, and executing the analysis with a simple Gradle command.
In a Spring Boot multi‑module project that uses Gradle 3.3, you can enable SonarQube 5.6.6 analysis by adding the SonarQube plugin and its repository to the root build.gradle file.
Repository and Plugin Dependency
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.3"
}
}Because the project is multi‑module, place this configuration in the outermost build.gradle.
Apply SonarQube Plugin to All Subprojects
subprojects {
sonarqube {
properties {
property "sonar.host.url", "http://localhost:9000/"
property "sonar.jdbc.url", "jdbc:mysql://my.server.com/sonar"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
}
}
apply plugin: 'org.sonarqube'
}Full Example of build.gradle
buildscript {
repositories { maven { url "https://plugins.gradle.org/m2/" } }
dependencies { classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.3" }
}
apply plugin: 'org.sonarqube'
apply plugin: 'idea'
group = 'com.bootcwenao'
version = '0.1.0-SNAPSHOT'
subprojects {
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
main { java.srcDir 'src/main/java'; resources.srcDir 'src/main/resources' }
test { java.srcDir 'src/test/java'; resources.srcDir 'src/test/resources' }
}
sonarqube {
properties {
property "sonar.host.url", "http://localhost:9000/"
property "sonar.jdbc.url", "jdbc:mysql://my.server.com/sonar"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.3'
}Running SonarQube
Start the SonarQube server (e.g., StartSonar.bat) and then execute the analysis with: gradle sonarqube -x test This command runs SonarQube analysis on all modules while skipping tests.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
