sonar-scala / sbt-sonar Goto Github PK
View Code? Open in Web Editor NEWAn sbt plugin which provides an easy way to integrate Scala projects with SonarQube.
Home Page: https://sonar-scala.com/docs/setup/sbt-sonar
License: Apache License 2.0
An sbt plugin which provides an easy way to integrate Scala projects with SonarQube.
Home Page: https://sonar-scala.com/docs/setup/sbt-sonar
License: Apache License 2.0
sbt sonarScan
doesn't seem to upload my generated report to sonar.
I did generate my scoverage report using sbt clean coverage test
as in the doc of scoverage.
I also already have a working sbt sonarScan
task which uploads all the analysis to SonarQube.
But i can't seem to se my scoverage report uploaded correctly. Values are null for scala coverage.
But if i open the report locally there are indeed some datas .
I tried many configuration for the reportPaths.
HEre is the latest
lazy val sonarSettings = Seq(
sonarProperties ++= Map(
"sonar.projectName" -> "myproject",
"sonar.modules" -> "module1,module2,module3",
"sonar.skippedModules" -> ".",
"sonar.scala.scoverage.reportPaths" -> "target/scoverage-report/scoverage.xml",
)
)
I also tried with sbt coverageAggregate
then the conf would theorically be
lazy val sonarSettings = Seq(
sonarProperties ++= Map(
"sonar.projectName" -> "myproject",
"sonar.modules" -> "module1,module2,module3",
"sonar.skippedModules" -> ".",
"sonar.scala.scoverage.reportPaths" -> "target/scala-2.12/scoverage-report/scoverage.xml",
)
)
Any idea on this one ?
Currently, when using an external config (sonarUseExternalConfig
) sbt-sonar doesn't accept system properties, but we should allow for this.
Hello
First, thanks for you help developing this plugin :)
Now, i run the sonarScan sbt task but no saca files are analized.
This is my conf file:
sonar.projectName=my-app
sonar.projectKey=my-team-app
sonar.sources=app
sonar.scala.version=2.11.1
sonar.host.url=http://backoffice.develop.it/sonarqube/
sonar.java.binaries=target
If i dont include the "sonar.java.binaries" property, the execution fails with: "Please provide compiled classes of your project with sonar.java.binaries property"
When i set that property, the scanner only checks java, js, css and html files. But no scala ones.
This is the output:
[info] Loading project definition from /Users/dev-user/Desarrollo/proyectos/my-app/project
[info] Set current project to my-app (in build file:/Users/dev-user/Desarrollo/proyectos/my-app/)
[info] INFO: Scanner configuration file: /private/tmp/sonar-scanner-3.2.0.1227-macosx/conf/sonar-scanner.properties
[info] INFO: Project root configuration file: /Users/dev-user/Desarrollo/proyectos/my-app/sonar-project.properties
[info] INFO: SonarQube Scanner 3.2.0.1227
[info] INFO: Java 1.8.0_121 Oracle Corporation (64-bit)
[info] INFO: Mac OS X 10.13.6 x86_64
[info] INFO: User cache: /Users/dev-user/.sonar/cache
[info] INFO: SonarQube server 6.7.1
[info] INFO: Default locale: "en_US", source code encoding: "UTF-8"
[info] INFO: Publish mode
[info] INFO: Load global settings
[info] INFO: Load global settings (done) | time=490ms
[info] INFO: Server id: AWHn2LOv4XHqZknEHeot
[info] INFO: User cache: /Users/dev-user/.sonar/cache
[info] INFO: Load plugins index
[info] INFO: Load plugins index (done) | time=325ms
[info] INFO: Process project properties
[info] INFO: Load project repositories
[info] INFO: Load project repositories (done) | time=245ms
[info] INFO: Load quality profiles
[info] INFO: Load quality profiles (done) | time=233ms
[info] INFO: Load active rules
[info] INFO: Load active rules (done) | time=3221ms
[info] INFO: Load metrics repository
[info] INFO: Load metrics repository (done) | time=236ms
[info] INFO: Project key: my-app
[info] INFO: ------------- Scan my-app
[info] INFO: Base dir: /Users/dev-user/Desarrollo/proyectos/my-app
[info] INFO: Working dir: /Users/dev-user/Desarrollo/proyectos/my-app/.scannerwork
[info] INFO: Source paths: app
[info] INFO: Source encoding: UTF-8, default locale: en_US
[info] INFO: Load server rules
[info] INFO: Load server rules (done) | time=1059ms
[info] INFO: Index files
[info] INFO: 188 files indexed
[info] INFO: Quality profile for java: Sonar way
[info] INFO: Quality profile for js: Sonar way
[info] INFO: Quality profile for web: Sonar way
[info] INFO: Sensor JavaSquidSensor [java]
[info] INFO: Configured Java source version (sonar.java.source): none
[info] INFO: JavaClasspath initialization
WARN: Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property
[info] INFO: JavaClasspath initialization (done) | time=16ms
[info] INFO: JavaTestClasspath initialization
[info] INFO: JavaTestClasspath initialization (done) | time=1ms
[info] INFO: Java Main Files AST scan
[info] INFO: 2 source files to be analyzed
[info] INFO: Java Main Files AST scan (done) | time=288ms
[info] INFO: 2/2 source files have been analyzed
[info] INFO: Java Test Files AST scan
[info] INFO: 0 source files to be analyzed
[info] INFO: 0/0 source files have been analyzed
[info] INFO: Java Test Files AST scan (done) | time=5ms
[info] INFO: Sensor JavaSquidSensor [java] (done) | time=847ms
[info] INFO: Sensor Embedded CSS Analyzer Sensor [css]
[info] INFO: 36 source files to be analyzed
[info] INFO: Sensor Embedded CSS Analyzer Sensor [css] (done) | time=223ms
[info] INFO: 36/36 source files have been analyzed
[info] INFO: Sensor SmellMeasuresSensor [smells]
[info] INFO: Sensor SmellMeasuresSensor [smells] (done) | time=26ms
[info] INFO: Sensor SonarJS [javascript]
[info] INFO: 1 source files to be analyzed
[info] INFO: Sensor SonarJS [javascript] (done) | time=79ms
[info] INFO: 1/1 source files have been analyzed
[info] INFO: Sensor SonarJS Coverage [javascript]
[info] INFO: Sensor SonarJS Coverage [javascript] (done) | time=2ms
[info] INFO: Sensor FindBugs Sensor [findbugs]
[info] INFO: Loading findbugs plugin: /Users/dev-user/Desarrollo/proyectos/my-app/.scannerwork/findbugs/findsecbugs-plugin.jar
[info] INFO: Findbugs output report: /Users/dev-user/Desarrollo/proyectos/my-app/.scannerwork/findbugs-result.xml
The following classes needed for analysis were missing:
scala.runtime.AbstractFunction0
scala.Serializable
scala.runtime.AbstractFunction1
scala.runtime.AbstractFunction2
com.despegar.routing.filter.ComponentProvider
scala.runtime.AbstractFunction0$mcV$sp
play.api.mvc.WithFilters
com.myproject.routing.filter.HeadersFilter
.....
.....
.....
[info] INFO: Sensor FindBugs Sensor [findbugs] (done) | time=56757ms
[info] INFO: Sensor SurefireSensor [java]
[info] INFO: parsing [/Users/dev-user/Desarrollo/proyectos/my-app/target/surefire-reports]
[info] INFO: Sensor SurefireSensor [java] (done) | time=4ms
[info] INFO: Sensor JaCoCoSensor [java]
[info] INFO: Sensor JaCoCoSensor [java] (done) | time=1ms
[info] INFO: Sensor SonarJavaXmlFileSensor [java]
[info] INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=2ms
[info] INFO: Sensor Web [web]
[info] INFO: Sensor Web [web] (done) | time=337ms
[info] INFO: Sensor Snyk Dependency Check Sensor [despegardepcheck]
[info] INFO: Snyk installation OK. Executing plugin.
[info] INFO: Sensor Snyk Dependency Check Sensor [despegardepcheck] (done) | time=20ms
[info] INFO: Sensor Retirejs Dependency Check Sensor [despegardepcheck]
WARN: Retire command not found
[info] INFO: Sensor Retirejs Dependency Check Sensor [despegardepcheck] (done) | time=14ms
[info] INFO: Sensor Zero Coverage Sensor
[info] INFO: Sensor Zero Coverage Sensor (done) | time=46ms
[info] INFO: Sensor CPD Block Indexer
[info] INFO: Sensor CPD Block Indexer (done) | time=18ms
[info] INFO: SCM provider for this project is: git
[info] INFO: 38 files to be analyzed
[info] INFO: 38/38 files analyzed
[info] INFO: 6 files had no CPD blocks
[info] INFO: Calculating CPD for 33 files
[info] INFO: CPD calculation finished
[info] INFO: Analysis report generated in 221ms, dir size=220 KB
[info] INFO: Analysis reports compressed in 319ms, zip size=118 KB
[info] INFO: Analysis report uploaded in 1660ms
[info] INFO: ANALYSIS SUCCESSFUL, you can browse http://backoffice.develop.it/sonarqube/dashboard/index/my-app
[info] INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[info] INFO: More about the report processing at http://backoffice.develop.it/sonarqube/api/ce/task?id=AWZeAEaDPe2FC9iyiYIB
[info] INFO: Task total time: 1:08.725 s
[info] INFO: ------------------------------------------------------------------------
[info] INFO: EXECUTION SUCCESS
[info] INFO: ------------------------------------------------------------------------
[info] INFO: Total time: 1:11.792s
[info] INFO: Final Memory: 34M/1593M
[info] INFO: ------------------------------------------------------------------------
[success] Total time: 73 s, completed Oct 10, 2018 9:42:48 AM
The line that call my atention is:
[info] INFO: 188 files indexed
Because I have 188 scala files
In the sonar report none Scla references appears
I missing something?
Thanks in advance for your help!
Hi,
I am currently working on implementing SonarQube quality gates on the pipelines of multiple projects to ensure that it's not possible to push code upstream or merge to master unless the new code is covered by tests. I am running sonarScan
against an aggregate project that contains all of the projects to be assessed, and there is a sonar scan stage in the pipeline that performs that check.
The current implementation of the quality gate runs sonar scan against all projects separately, as well as against an aggregated project that is used for the gate check. Currently there is an issue that is occurring on the pipeline where running sonarScan results in an OverlappingFileLockException It runs sonarScan against all of the projects in the aggregated project, and this error is thrown on the second project, regardless as to which project this is.
Any help on this matter would be much appreciated.
I took the multi-module test project and added code which successfully triggered ScapeGoat. However, this information was not pushed up to SonarQube. I would expect to see the warnings under code smells, as I do for ScalaStyle issues.
https://github.com/mwz/sbt-sonar/tree/master/src/sbt-test/sbt-sonar/multi-module
I'm running SonarQube 6.7.5
on sbt sonarScan
it always fails few seconds after doing great, because of this
ERROR: com.mwz.sonar.scala.scalastyle.ScalastyleSensor has unsatisfied dependency 'class org.sonar.api.profiles.RulesProfile' for constructor 'public com.mwz.sonar.scala.scalastyle.ScalastyleSensor(org.sonar.api.profiles.RulesProfile,com.mwz.sonar.scala.scalastyle.ScalastyleCheckerAPI)' from org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer@67a056f1:112<[Immutable]:org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer@35a3d49f:462<[Immutable]:org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer@2c768ada:52<|
Can we "bypass" these ?!
In a Scala project, it is common to have also Java code, in addition to Javascript and other languages.
Analyze also Java code.
Seeing very strange error when running sonarqube in CI, not clear what could be causing it.
ran this command in CI:
sbt -Dsonar.pullrequest.branch=${GITHUB_REF#refs/heads/} -Dsonar.pullrequest.key=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") -Dsonar.pullrequest.base="main" -Dsonar.login="$SONAR_CI_TOKEN" "service/sonarScan"
java.lang.IllegalAccessError: class org.sonarsource.scala.checks.DuplicateBranchScalaCheck$$Lambda$5577/0x00000008020cdb00 tried to access protected method 'boolean org.sonarsource.slang.checks.DuplicateBranchCheck.spansMultipleLines(org.sonarsource.slang.api.Tree)' (org.sonarsource.scala.checks.DuplicateBranchScalaCheck$$Lambda$5577/0x00000008020cdb00 and org.sonarsource.slang.checks.DuplicateBranchCheck are in unnamed module of loader org.sonar.classloader.ClassRealm @77a5a495)
[error] at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
[error] at java.base/java.util.stream.SliceOps$1$1.accept(SliceOps.java:199)
[error] at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
[error] at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
[error] at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
[error] at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
[error] at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
[error] at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[error] at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
[error] at org.sonarsource.scala.checks.DuplicateBranchScalaCheck.checkDuplicatedBranches(DuplicateBranchScalaCheck.java:50)
[error] at org.sonarsource.slang.checks.AbstractBranchDuplicationCheck.checkConditionalStructure(AbstractBranchDuplicationCheck.java:57)
[error] at org.sonarsource.slang.checks.AbstractBranchDuplicationCheck.lambda$initialize$1(AbstractBranchDuplicationCheck.java:49)
[error] at org.sonarsource.slang.plugin.ChecksVisitor$ContextAdapter.lambda$register$0(ChecksVisitor.java:68)
[error] at org.sonarsource.slang.visitors.TreeVisitor$ConsumerFilter.accept(TreeVisitor.java:87)
[error] at org.sonarsource.slang.visitors.TreeVisitor$ConsumerFilter.access$000(TreeVisitor.java:74)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:50)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.lambda$visit$0(TreeVisitor.java:53)
[error] at java.base/java.lang.Iterable.forEach(Iterable.java:75)
[error] at org.sonarsource.slang.visitors.TreeVisitor.visit(TreeVisitor.java:53)
[error] at org.sonarsource.slang.visitors.TreeVisitor.scan(TreeVisitor.java:40)
[error] at org.sonarsource.slang.plugin.SlangSensor.lambda$analyseFile$1(SlangSensor.java:129)
[error] at org.sonarsource.slang.plugin.DurationStatistics.time(DurationStatistics.java:64)
[error] at org.sonarsource.slang.plugin.SlangSensor.analyseFile(SlangSensor.java:129)
[error] at org.sonarsource.slang.plugin.SlangSensor.analyseFiles(SlangSensor.java:91)
[error] at org.sonarsource.slang.plugin.SlangSensor.execute(SlangSensor.java:166)
[error] at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
[error] at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
[error] at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
[error] at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
[error] at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
[error] at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
[error] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
[error] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
[error] at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:389)
[error] at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:385)
[error] at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:354)
[error] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
[error] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
[error] at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
[error] at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
[error] at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
[error] at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
[error] at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
[error] at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
[error] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] at java.base/java.lang.reflect.Method.invoke(Method.java:564)
[error] at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
[error] at com.sun.proxy.$Proxy20.execute(Unknown Source)
[error] at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
[error] at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
[error] at sbtsonar.SonarPlugin$.useEmbeddedScanner(SonarPlugin.scala:253)
[error] at sbtsonar.SonarPlugin$.$anonfun$projectSettings$5(SonarPlugin.scala:110)
[error] at sbtsonar.SonarPlugin$.$anonfun$projectSettings$5$adapted(SonarPlugin.scala:84)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] at sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] at sbt.Execute.work(Execute.scala:291)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
[error] at java.base/java.lang.Thread.run(Thread.java:832)
[error] (service / sonarScan) java.lang.IllegalAccessError: class org.sonarsource.scala.checks.DuplicateBranchScalaCheck$$Lambda$5577/0x00000008020cdb00 tried to access protected method 'boolean org.sonarsource.slang.checks.DuplicateBranchCheck.spansMultipleLines(org.sonarsource.slang.api.Tree)' (org.sonarsource.scala.checks.DuplicateBranchScalaCheck$$Lambda$5577/0x00000008020cdb00 and org.sonarsource.slang.checks.DuplicateBranchCheck are in unnamed module of loader org.sonar.classloader.ClassRealm @77a5a495)
Any suggestions as to what could cause this?
When upgrading to SonarQube server version: 9.1.0 with a Java 1.8 project, I receive this error when trying to scan my project:
[error] (sonarScan) java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runti
me only recognizes class file versions up to 52.0
I've read the documentation, and this is because the default sonar-scanner is now using JDK 11. There is a very simple way to get around this explained here: https://docs.sonarqube.org/latest/analysis/languages/java/#header-2
This is the important part:
In some situations, you might have to analyze a project built with a different version of Java than the one executing the analysis. The most common case is to run the analysis with Java 11, while the project itself uses Java 8 or before for its build. This case is normally automatically handled when using Maven or Gradle, as well as with any flavor of SonarLint. If it is your case, and you are NOT using Maven or Gradle, you will need to set the property sonar.java.jdkHome manually (see below).
I tried to provide this variable both in the build.sbt and in the command line. It is totally ignored by the plugin and the build always show the same error.
Here is an example of the command line used:
sbt -Dsonar.host.url=https://my-sonarqube.com -Dsonar.login=whatever -Dsonar.java.jdkHome=/usr/lib/jvm/java-1.8.265 sonarScan
Is this a bug? Is there any other way to analyse using java 8 instead of java 11?
Thanks
By now sbt-sonar does not seem to support "Server authentication token" that are provided by "SonarQube servers" from jenkins.
Did I miss something?
I highly doubt this has anything to do with the sbt plugin and is likely an error in the travis ci addon however I was wondering if you had experienced the issue I raised here. I started to see it when I updated to the latest release of sbt-sonar (1.7.0) https://travis-ci.community/t/sonar-addon-doesnt-set-environment-variables/3654?u=chocpanda
Setting sonar.scala.version through sonarProperties doesn't seem to work :/
My build.sonar.sbt looks like:
import sbtsonar.SonarPlugin.autoImport.sonarProperties
sonarProperties ++= Map(
"sonar.scala.version" -> "2.12.8",
"sonar.projectName" -> "ticket-server",
"sonar.projectKey" -> "ticket-server",
"sonar.sources" -> "src/main/scala",
"sonar.host.url" -> "http://localhost:9000",
"sonar.sourceEncoding" -> "UTF-8"
)
But in my output I get multiple warnings about it not being set:
[info] INFO: Sensor Scala Sensor [scala]
WARN: [sonar-scala] The 'sonar.scala.version' is not properly set or is missing, using the default value: '2.12.'.
[info] INFO: Sensor Scala Sensor [scala] (done) | time=127ms
...
[info] INFO: Sensor Scapegoat Sensor [scala]
WARN: [sonar-scala] The 'sonar.scala.version' is not properly set or is missing, using the default value: '2.12.'.
[info] INFO: [scapegoat] Initializing the Scapegoat sensor.
...
[info] INFO: [scoverage] Initializing the scoverage sensor.
WARN: [sonar-scala] The 'sonar.scala.version' is not properly set or is missing, using the default value: '2.12.'.
[info] INFO: [scoverage] Loading the scoverage report file: 'target/scala-2.12/scoverage-report/scoverage.xml'.
I've tried setting the value to: 2.12
. 2.12.8
, and even 2.12.
(as that's how the default is written in the error)
Currently, sonar-scanner
executable needs to be on the PATH, but we could fall back to use /bin
in sonar scanner home directory to look up the executable if sonar-scanner
isn't on the PATH.
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?
I have your docker-container with sonarqube (https://github.com/mwz/sonar-scala-docker) running.
I'd like to analyse my sbt
project with it, but I'm struggling with this part.
For a maven mroject I can simply use this: mvn sonar:sonar -Dsonar.host.url=http://localhost:9000
Is there analogue for sbt?
I added addSbtPlugin("com.github.mwz" % "sbt-sonar" % "1.6.0")
to my plugins, but the line
sbt -Dsonar.projectName=dev-projectName sonarScan
does not work for me and complains about SONAR_SCANNER_HOME
. Seems sonar-scanner
indeed has to be installed at my machine. Can I avoid that?
The ideal case would be cloning repository and running an sbt command to analyse it with remote sonar instance. Is it possible to do that?
I am using sbt-sonar version 1.7
. The report generation works fine & publishes to Sonarqube. After the report is published sbt-sonar returns with an exit code of 1 which causes the build to fail.
Command executed sbt +clean +package +coverage +test +coverageReport sonarScan
Here is the exception log
[info] INFO: ------------- Run sensors on project
[info] INFO: Sensor Zero Coverage Sensor
[info] INFO: Sensor Zero Coverage Sensor (done) | time=1ms
[info] INFO: 1 file had no CPD blocks
[info] INFO: Calculating CPD for 6 files
[info] INFO: CPD calculation finished
[info] INFO: Analysis report generated in 82ms, dir size=196 KB
[info] INFO: Analysis report compressed in 45ms, zip size=50 KB
[info] INFO: Analysis report uploaded in 127ms
[info] INFO: ANALYSIS SUCCESSFUL, you can browse https://sonar.mycompany.com/dashboard?id=key%3Ascv
[info] INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[info] INFO: More about the report processing at https://sonar.mycompany.com/api/ce/task?id=AWuudVQx0SSBxUIOMGwC
[info] INFO: Analysis total time: 11.438 s
[info] INFO: ------------------------------------------------------------------------
[info] INFO: EXECUTION SUCCESS
[info] INFO: ------------------------------------------------------------------------
[info] INFO: Total time: 14.328s
[info] INFO: Final Memory: 58M/820M
[info] INFO: ------------------------------------------------------------------------
[error] java.lang.RuntimeException: Nonzero exit code: 1
[error] at scala.sys.package$.error(package.scala:26)
[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:1167)
[error] at scala.collection.immutable.Stream$Cons.tail(Stream.scala:1157)
[error] at scala.collection.immutable.Stream.foreach(Stream.scala:530)
[error] at sbtsonar.SonarPlugin$.$anonfun$projectSettings$3(SonarPlugin.scala:77)
[error] at sbtsonar.SonarPlugin$.$anonfun$projectSettings$3$adapted(SonarPlugin.scala:52)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error] at sbt.std.Transform$$anon$4.work(System.scala:67)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error] at sbt.Execute.work(Execute.scala:278)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[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)
[error] at java.lang.Thread.run(Thread.java:745)
[error] (moduleA / sonarScan) Nonzero exit code: 1
Build.sbt
name := "lib-xyz"
inThisBuild(Seq(
organization := "my-org",
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-language:postfixOps",
"-language:higherKinds",
"-language:implicitConversions",
"-Ypartial-unification"
)
))
lazy val root = project.in(file("."))
.settings(
moduleName := "root"
)
.aggregate(moduleA)
.settings(sonarSettings)
lazy val moduleA = project
.settings(
libraryDependencies ++= Seq(
cats.core, cats.effect,
http4sAsyncClient, http4sDsl, fs2core, fs2io,
jsoup, scalaTestInTests, journal
),
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.9"),
publishMavenStyle := true,
publishArtifact := true,
)
lazy val sonarSettings = Seq(
sonarProperties ++= Map(
"sonar.projectName" -> "myproject",
"sonar.projectKey" -> "key:myproject",
"sonar.modules" -> "moduleA",
"module1.sonar.projectName" -> "moduleA",
"sonar.sources" -> "src/main/scala",
"sonar.junit.reportPaths" -> "target/test-reports",
"sonar.scala.coverage.reportPaths" -> "target/scala-2.12/scoverage-report/scoverage.xml",
"sonar.java.binaries" -> "target/scala-2.12/classes",
"sonar.login" -> "69174626AF5144E9A43DE60CFCADF646",
"sonar.host.url" -> "https://sonar.mycompany.com",
)
)
The sonar-scanner-api project provides an embedded sonar scanner, which we can use instead of delegating the scan to the cli executable.
Even with the below settings in sbt
sonarScan still looks for a report path in 2.11 and I get the following error:
java.io.FileNotFoundException:
/target/scala-2.11/scoverage-report/scoverage.xml (No such file or directory)
My sonar properties:
lazy val sonarSettings: Map[String, String] = Map(
"sonar.scala.version" -> "2.12",
"sonar.projectName" -> "project-name",
"sonar.projectKey" -> "project-key",
"sonar.modules" -> "module1,module2,module3",
"module1.sonar.projectName" -> "module1",
"module2.sonar.projectName" -> "module2",
"module3.sonar.projectName" -> "module3",
"sonar.sources" -> "src/main/scala",
"sonar.tests" -> "src/test/scala",
"sonar.projectVersion" -> "1.0.0",
"sonar.sourceEncoding" -> "UTF-8",
"sonar.host.url" -> sonarUrl,
"sonar.login" -> sonarToken
I also can confirm the right settings from sbt using show sonarProperties
pointing correctly to the 2.12 directory. Where is the 2.11 path coming from? Also tried to explicitly set sonar.scala.scoverage.reportPath
with same result. Not sure what I'm missing.
I have a project with many multiple modules. These modules are organised under subfolders like this:
my-project-root
src
main
scala
subfolder-1
module-1
src
main
scala
subfolder-2
module-2
src
main
scala
with the main module directly under root directory, a module under subfolder-1/module-1
and a second module under subfolder-2/module-2
.
sonarScan fails in this configuration :
module-1
instead of subfolder-1/module-1
sonar.projectBaseDir
on each module, but do not declare them as submodules, it workssonar.projectBaseDir
and declare submodules, it fails.It seems it needs the sonar.projectBaseDir
under each module, and in case of module aggregation under the main module, it needs a module1.sonar.projectBaseDir
for each module.
I will provide a PR putting this in evidence.
This is a custom key introduced in sonar-scala/sonar-scala#17 which, in the future, will allow the sonar-scala plugin to interpret sources using different versions of Scala in different ways - currently, Scaliform doesn't provide any specific lexer rules for Scala 2.12.
Now if some test fails in you Spec.scala and you publish this report to sonar, you will see only the failed Spec.file but not specific failed test.
It is very actual when you have integration tests
I get an error when I try to execute sbt task sonarScan
[error] (sonarScan) java.io.IOException: Cannot run program "%SONAR_SCANNER_HOME%\bin\sonar-scanner": CreateProcess error=2, The system cannot find the file specified
I have created 'SONAR_SCANNER_HOME' environment variable. sonar-scanner.bat does exists under mentioned path; but it still complains.
I think the issue with this piece of code:
val sonarScanner = Paths.get(sonarHome).resolve("bin/sonar-scanner").toAbsolutePath.toString
Using:
sbt-sonar: v1.4.0
sonar-scanner: sonar-scanner-3.2.0.1227-windows
When running scripted
command, it fails when fetching sbt 1.0.3 while it is running with sbt 1.5.0.
The Scoverage report path property sonar.scoverage.reportPath
was deprecated in sonar-scala 6.2.0 and we should use the new propertysonar.scala.scoverage.reportPath
instead.
After much trial and error as to why my project would not find reports generated by scoverage, I discovered that the property sonar.scala.coverage.reportPaths
worked, whereas the property sonar.scala.scoverage.reportPath
, as written in documentation, did not.
For reference this is a scala 2.12 project, using sbt-sonar 2.1.0 and sbt-scoverage 1.6.0
Hello everybody,
I want to use sbt sonar for analyzing projects. However, the plugin is not able to pick up the scoverage information and display it in sonar for my sbt project. There is one caveat, I have a multi module build and all of my modules are in a subfolder called modules. (Please find attached sample project which is reproducing the error https://github.com/mwz/sbt-sonar/files/2335828/multi-module-new.zip)
I essentially changed the sample project from here 47126c4 and moved all the submodules in the submodule folder.
I'm running the sonnar scanner
sbt -Dsonar.host.url=http://localhost:80 -Dsonar.projectBaseDir=modules -Dsonar.sources=src/main/scala -Dsonar.scoverage.reportPath=target/scala-2.12/scoverage-report/scoverage.xml clean coverage test coverageReport sonarScan
Not producing any coverage information in sonar, just producing the warning:
WARN: [scoverage] The property: 'sonar.scoverage.reportPath' is deprecated, use the new property 'sonar.scala.scoverage.reportPath' instead.
[info] INFO: [scoverage] Loading the scoverage report file: 'modules/module1/target/scala-2.12/scoverage-report/scoverage.xml'.
[info] INFO: [scoverage] Successfully loaded the scoverage report file.
WARN: [scoverage] The file 'module1/src/main/scala/Example1.scala' has no scoverage information associated with it.
Running it on the subproject does not make any difference:
sbt -Dsonar.host.url=http://localhost:80 -Dsonar.projectBaseDir=modules -Dsonar.sources=src/main/scala -Dsonar.modules=module1 -Dsonar.scoverage.reportPath=target/scala-2.12/scoverage-report/scoverage.xml "project module1" clean coverage test coverageReport sonarScan
Note:
Using the docker sonar image sonarqube:6.7.5-alpine via docker compose up. (from here https://github.com/mwz/sonar-scala-docker)
SONAR_SCANNER_HOME can only be set as an env variable and this causes quite a bit of issues in a build pipeline where you don't necessarily have that much control. Such that I can't set it at all and can't use it an similar build server to the bitbucket pipeline. If I could set it as a property that would be much easier.
Thanks for the plugin!
First off, great project, thanks for the awesome work you have done ๐
However, the learning curve was rather steep. My initial project/build.properties had sbt.version set to 1.2.1 which doesn't seem to work (is that due to: crossSbtVersions := Seq("0.13.17", "1.1.6")
?). At least it seems to work with both 0.13.17 and 1.1.6. If a correct version is a requirement that would be nice to know.
As I ran in to your plugin fairly early in my Scala learning process (well tools like these are good for learning good practices) I'm far from experienced in sbt, I was confused about where to put the sonarProperties ++= Map(...
, seems that build.sbt is the right place, although googling also showed that I can do something like build.sonar.sbt :) That would probably be a very helpful addition to other newcomers.
Having a fully working minimal example of the use would be a very nice addition. Could be in a folder named examples, or something similar.
I think that was my getting started observations. Once again, thanks a lot for this great project
I have:
addSbtPlugin("com.sonar-scala" % "sbt-sonar" % "2.3.0")
I have:
sonarProperties ++= Map(
"sonar.host.url" -> "https://sonar.mydomain.com",
"sonar.login" -> "admin",
"sonar.password" -> "secret",
)
subproject/sonarProperties ++= Map(
"sonar.host.url" -> "https://sonar.mydomain.com",
"sonar.login" -> "admin",
"sonar.password" -> "secret",
)
Then:
show sonarProperties
subproject / sonarProperties
[info] Map(sonar.scala.scapegoat.reportPath -> target/scapegoat-report/scapegoat.xml, sonar.sources -> src/main/scala, sonar.sourceEncoding -> UTF-8, sonar.projectName -> subproject, sonar.projectBaseDir -> /sv/subproject, sonar.tests -> src/test/scala, sonar.projectKey -> subproject, sonar.scala.version -> 2.13.7, sonar.scala.scoverage.reportPath -> target/scoverage-report/scoverage.xml)
sonarProperties
Map(sonar.scala.scapegoat.reportPath -> target/scala-2.12/scapegoat-report/scapegoat.xml, sonar.sources -> src/main/scala, sonar.sourceEncoding -> UTF-8, sonar.login -> admin, sonar.password -> secret, sonar.projectName -> TodoVision, sonar.projectBaseDir -> /sv, sonar.host.url -> https://sonar.domain.com, sonar.tests -> src/test/scala, sonar.projectKey -> todovision, sonar.scala.version -> 2.12.16, sonar.scala.scoverage.reportPath -> target/scala-2.12/scoverage-report/scoverage.xml)
If I try to run subproject/sonarScan
then it tries to access http://localhost/9000
instead of my customized server.
SBT version 1.7.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.