sonar-scala / sbt-sonar

An sbt plugin which provides an easy way to integrate Scala projects with SonarQube.

Home Page:https://sonar-scala.com/docs/setup/sbt-sonar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't find source folder

ricardoatsouza opened this issue · comments

I have a scala project with sub-projects (modules). My configurations for the sonar are:

sonarProperties := Map(
  "sonar.projectName" -> "Fancy Project Name",
  "sonar.projectKey" -> "FancyKey",
  "sonar.projectVersion" -> a_version,
  "sonar.sources" -> "src/main/scala",
  "sonar.sourceEncoding" -> "UTF-8",
  "sonar.modules" -> "m1,m2,m3,m4",
  "m1.sonar.projectName" -> "Module 1",
  "m2.sonar.projectName" -> "Module 2",
  "m3.sonar.projectName" -> "Module 3",
  "m4.sonar.projectName" -> "Module 4"
)

The directory structure follows the sbt recommendations.

./projectFolder
|- m1
|  `- src
|     `- main
|        |- scala
|        |  `- Main.scala
|        `- resources
|- m2
|  `- src
|     `- main
|        |- scala
|        |  `- Main.scala
|        `- resources
|- m3
|  `- src
|     `- main
|        |- scala
|        |  `- Main.scala
|        `- resources
`- m4
   `- src
      `- main
         |- scala
         |  `- Main.scala
         `- resources

But, when I execute sbt sonarScan, I get in the stderr:

ERROR: Invalid value of sonar.sources for m1
ERROR: Invalid value of sonar.sources for m2
ERROR: Error during SonarQube Scanner execution
ERROR: The folder 'src/main/scala' does not exist for 'm1' (base directory = /Users/username/projectFolder)
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: Error during SonarQube Scanner execution
ERROR: The folder 'src/main/scala' does not exist for 'm2' (base directory = /Users/username/projectFolder)
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: Invalid value of sonar.sources for m3
ERROR: Error during SonarQube Scanner execution
ERROR: The folder 'src/main/scala' does not exist for 'm3' (base directory = /Users/username/projectFolder)
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
ERROR: Invalid value of sonar.sources for m4
ERROR: Error during SonarQube Scanner execution
ERROR: The folder 'src/main/scala' does not exist for 'm4' (base directory = /Users/username/projectFolder)
ERROR: 
ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
WARN: [scoverage] Report path not set for Module 1 module! [Module 1.sonar.scoverage.reportPath]
WARN: [scoverage] Report path not set for Module 2 module! [Module 2.sonar.scoverage.reportPath]
WARN: [scoverage] Report path not set for Module 3 module! [Module 3.sonar.scoverage.reportPath]
WARN: [scoverage] Report path not set for Module 4 module! [Module 4.sonar.scoverage.reportPath]

And it ends with some more errors in the stdout (it shows this 4x, once per project):

[error] java.lang.RuntimeException: Nonzero exit code: 1
[error] 	at scala.sys.package$.error(package.scala:27)
[error] 	at scala.sys.process.BasicIO$Streamed$.next$1(BasicIO.scala:49)
[error] 	at scala.sys.process.BasicIO$Streamed$.$anonfun$apply$1(BasicIO.scala:50)
[error] 	at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1169)
[error] 	at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1159)
[error] 	at scala.collection.immutable.Stream.foreach(Stream.scala:531)
[error] 	at sbtsonar.SonarPlugin$.$anonfun$projectSettings$3(SonarPlugin.scala:59)
[error] 	at sbtsonar.SonarPlugin$.$anonfun$projectSettings$3$adapted(SonarPlugin.scala:41)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:42)
[error] 	at sbt.std.Transform$$anon$4.work(System.scala:64)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:257)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] 	at sbt.Execute.work(Execute.scala:266)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:257)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:167)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:32)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error] 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

Any ideas of what could be wrong?

Btw, using Scala 2.12.3, SonarQube 6.7.1, and Sbt-sonar 1.3.0.

Hi @ricardoatsouza, thanks for the shout - I'll have a look. I've used sonar with multi-module projects without any issues in the past, so it might be just a misconfiguration.
I was planning to add a multi-module example to sbt tests, so this is a perfect opportunity to do this.

Hi @mwz , thanks for the answer.
I'm also almost 100% convinced that this looks like a misconfiguration.

The annoying think is that I don't know where it is. Looking at the documentation, everything seems to be fine (well... we know how that goes :D ). So, if you have any ideas of where I should look into, let me know.

Thanks

It looks all good on my end... I think your problem might be related to how you configured the project in your build.sbt. Also, you want sonnarScan to be run only once for your root project, so you need to exclude the task from the aggregation by setting aggregate in sonarScan to false.
I just added an example multi-module project, which you can use as a reference 47126c4.

Adding .settings(aggregate in sonarScan := false) does the job. Thanks. 👍

Now, I'm facing another issue. Somehow sonar-scanner cannot find scoverage.xml.
I keep seeing this in the logs:

ERROR: [scoverage] Report not found at /Users/username/Development/projectFolder/module-1/target/scala-2.12/scoverage-report
WARN: [scoverage] Report path not set for Module 1 module! [Module 1.sonar.scoverage.reportPath]

However, a ls module-1/target/scala-2.12/scoverage-report shows me that the file is there:

index.html     ingestion      ingestion.html overview.html  packages.html  scoverage.xml

I'm aware that this problem is not related to sbt-sonar, but since we are in this chat, do you have a better idea of why this might be happening?

Actually, by setting manually the properties reportPath for both sub-projects solved the issue. Basically, what I did was adding these two lines to my build.sbt, in the sonarProperties variable:

  "module-1.sonar.scoverage.reportPath" -> "target/scala-2.12/scoverage-report/scoverage.xml",
  "module-2.sonar.scoverage.reportPath" -> "target/scala-2.12/scoverage-report/scoverage.xml",

Funny thing is: setting manually those variables should not actually be necessary, since this path was already being logged before. But this solution will solve it for now.

As a final check, I will update the Scala plugin in Sonarqube.

Just to report it here.

I created a new jar file from the master branch for the Scala plugin I'm using (Sagacify/sonar-scala) and updated it in Sonarqube. But, still, the property <sub-project>.sonar.scoverage.reportPath were needed to be defined manually.

If this is a issue in the plugin, or a misconfiguration on my side, it's still unclear. But since I did this small investigation, it's nice to report it here, so others might find this useful.

@mwz Thanks for the help! This issue can be happily closed. :)

Thanks @ricardoatsouza for digging a little bit deeper.
I'd recommend sticking to SonarQube 5.6.7 for now until the sonar-scala plugin is compatible with 6.7.1 LTS. I've been doing some work in my fork of the project and I'm planning to make a release once it's ready, so you can keep an eye on sonar-scala/sonar-scala#5.
Your issues might be also related to how you set up your sbt project but it's difficult to say without seeing the config.
I think we can also improve sbt-sonar to automatically set sonar.sources, sonar.scoverage.reportPath and sonar.scala.scapegoat.reportPath for each module so you don't need to set this up manually (#9).

@mwz Nice to hear that there are good stuff coming :)
Thanks for your support. I will have this repo in my watch list.
Cheers!