SonarQubeProperties in gradle plugin 3.3 help

My sonarqube gradle task is not setting the properties properly. It is still trying to post/connect to localhost:9000. According to this link, I should be able to do the following?

val sonarProperties = SonarQubeProperties(
                    mapOf(
                            "sonar.host.url" to "https://mysonar.cloud.com",
                            "sonar.login" to "my token",
                            "sonar.sourceEncoding" to "UTF-8",
                            ...
                    )
)

val sonarExt: SonarQubeExtension = project.extensions.getByName("sonarqube") as SonarQubeExtension

sonarExt.properties(sonarProperties)

Does anyone have any idea :grinning:?

Hi @Riad_Gaffar ,

Welcoem to SonarSource Community! :sonarsource:

Have you set your Administration > Configuration > General > Server Base URL? Set it and try the scan again:

Joe

Don’t have Admin access. Works fine if I pass it in via cli.
./gradlew sonarqube -Dsonar.host.url=https://mysonar.cloud.com...

also added them to gradle properties and they are being loaded; however, seems like sonarqube plugin/scanner is not picking them up. Also tried systemProp.sonar.host.url, same result

Ok, I see what you mean now. You are using Kotlin DSL in your build.gradle.kts.

Maybe this thread will help:

I started in that thread and tried using the SonQubeExtention example but that didn’t work. Seem like this might be the work around from that thread? How/where do I use/apply the SonarPlugin class?

So I was able to get it working this way

allprojects {
  sonarqube {
    properties {
      property("sonar.host.url", "https://mysonar.cloud.com")
      property("sonar.login", "my token")
      property("sonar.sourceEncoding", "UTF-8")
      ...
    }
  }
}

But no coverage data. Any idea?

I’ve got these properties:

property("sonar.sources", "$sourceDirectories")
property("sonar.tests", "$projectDir/src/test/java/com/pkg/module")
property("sonar.test.inclusions", "$projectDir/src/test/java")
property("sonar.java.binaries", "$binaries")
property("sonar.coverage.jacoco.xmlReportPaths", "$xmlReport")
property("sonar.jacoco.reportPaths", "$jacocoReportsPath")
property("sonar.junit.reportPaths", "$unitTestReportsPath")
property("sonar.cpd.exclusions", "**")

Hi @Riad_Gaffar ,

Thanks for the update on what worked to get the properties working.

Please read through our Community Guide in the “Gradle” section about importing Jacoco coverage report: [Coverage & Test Data] Importing JaCoCo coverage report in XML format

Here’s a simple Gradle project to see how it works: https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-gradle/gradle-basic

Do you have a Gradle multimodule project? If so, please check out my project example: https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-gradle/gradle-multimodule-coverage

For further questions, please create a new topic since your original issue has been resolved.

Regards,
Joe