Sonar sbt plugin is pointing to localhost:9000 despite mentioning a different sonar url

I am using SonarCE version 9.7 along with sonar sbt plugin, I have setup my config for a scala project in the build.sbt for the following format:
sonarProperties := Map(
“sonar.host.url” → “https://sonarqube.hub.company.com”,
“sonar.projectKey” → “com-xxx-data”,
“sonar.login” → “******”,
“sonar.language” → “scala”,
“sonar.verbose” → “true”,
“sonar.sourceEncoding” → “UTF-8”,
“sonar.projectName” → “CatService”,
“sonar.modules” → “service,dataMigration”,
“service.sonar.projectName” → “service”,
“dataMigration.sonar.projectName” → “dataMigration”,
“service.sonar.sources” → “src/main/scala”,
“service.sonar.tests” → “src/test/scala”,
“service.sonar.scala.coverage.reportPaths” → “target/scala-2.13/scoverage-report/scoverage.xml”,
“service.sonar.scala.scapegoat.reportPath” → “target/scala-2.13/scapegoat-report/scapegoat.xml”,
“dataMigration.sonar.sources” → “src/main/scala”,
“dataMigration.sonar.scala.coverage.reportPaths” → “target/scala-2.13/scoverage-report/scoverage.xml”,
“dataMigration.sonar.scala.scapegoat.reportPath” → “target/scala-2.13/scapegoat-report/scapegoat.xml”
)
The project runs fine and I am successfully able to import results to my hosted sonar instance, but I always see an error:
[error] SonarQube server [http://localhost:9000] can not be reached
[error] SonarQube server [http://localhost:9000] can not be reached

followed by:
org.sonarsource.scanner.api.internal.ScannerException: Unable to execute SonarScanner analysis
[error] at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.lambda$createLauncher$0(IsolatedLauncherFactory.java:85)
[error] at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
[error] at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:74)
[error] at org.sonarsource.scanner.api.internal.IsolatedLauncherFactory.createLauncher(IsolatedLauncherFactory.java:70)
[error] at org.sonarsource.scanner.api.EmbeddedScanner.doStart(EmbeddedScanner.java:185)
[error] at org.sonarsource.scanner.api.EmbeddedScanner.start(EmbeddedScanner.java:123)

I tried to override the config by using the -D flag and it works but somehow the build.sbt is not able to override the localhost url. How do I override this value in my config?

Hey there.

You probably want to get in touch with the maintainers of the SBT plugin at GitHub - sonar-scala/sbt-sonar: An sbt plugin which provides an easy way to integrate Scala projects with SonarQube.

Hi Colin! Thank you for the response, I figured out this issue myself, here’s how to fix it if someone still faces the same issue:

This issue is caused for a multi module project due to misconfiguration of the project in the build.sbt, there are a few examples that might help: sbt-sonar/src/sbt-test/sbt-sonar at master · sonar-scala/sbt-sonar · GitHub

The following is the config that worked for me:

This enabled the plugin to detect and report all modules to the root setup.

2 Likes