Must-share information (formatted with Markdown):
- which versions are you using: SonarQube Community Build
- how is SonarQube deployed: locally on my Linux machine
- what are you trying to achieve: just want to test it out
- what have you tried so far to achieve this: I Googled everywhere
I have 5 separate Gradle modules in my Android project. I wish to apply sonar to all of them. Here is what I have tried so far.
I am using Version Catalogs. For Sonar, I have the following entries:
[versions]
sonarQubeVersion = "6.0.1.5171"
sonarScannerVersion = "3.3"
[libraries]
sonarGradlePluginLibrary = { group = "org.sonarsource.scanner.gradle", name = "sonarqube-gradle-plugin", version.ref = "sonarScannerVersion" }
[plugins]
sonarQubePlugin = { id = "org.sonarqube", version.ref = "sonarQubeVersion" }
In my project’s build.gradle.kts:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.sonarQubePlugin) apply false
}
In my convention build.gradle.kts:
dependencies {
compileOnly(libs.sonarGradlePluginLibrary)
}
In my custom plugin:
class AppPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
alias(libs.plugins.sonarQubePlugin)
}
configureSonar()
}
}
}
Where configureSonar is:
import org.gradle.api.Project
import org.gradle.kotlin.dsl.findByType
import org.sonarqube.gradle.SonarQubeExtension
internal fun Project.configureSonar() {
pluginManager.apply(libs.plugins.sonarQubePlugin.get().pluginId)
val sonarExtension = extensions.findByType<SonarQubeExtension>()
sonarExtension?.apply {
properties {
property("sonar.projectName", "Project Name")
property("sonar.projectKey", "Project-Name")
property("sonar.language", "kotlin")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.host.url", "http://localhost:9000")
property("sonar.token", "my-token")
}
} ?: println("there was a problem applying Sonar")
}
Now, when I refresh Gradle, I get the following error regarding the SonarQubeExtension import:
Unable to load class 'org.sonarqube.gradle.SonarQubeExtension'
org.sonarqube.gradle.SonarQubeExtension
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I have tried refreshing all gradle imports but still the same error. Can someone tell me where I am making a mistake?