sonar-scala / sonar-scala

A free and open-source SonarQube plugin for static code analysis of Scala projects.

Home Page:https://sonar-scala.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to build the Project multi-module

sanjaymp18 opened this issue · comments

Hello, exactly clone the files under the multi-module and ran the below pipeline script

node() {
    properties([
        buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '20')),
        disableConcurrentBuilds()
    ])

    stage('Lint') {
        sh '''
        export MAVEN_HOME=/opt/apache-maven
        export PATH=$PATH:$MAVEN_HOME/bin
        mvn --version
        mvn -Dsonar.host.url=http://localhost:9000 clean test scoverage:report scala:compile  sonar:sonar
            '''
    }
}

Build Output :

Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/test-scala-module
[Pipeline] {
[Pipeline] properties
[Pipeline] stage
[Pipeline] { (Lint)
[Pipeline] sh
+ export MAVEN_HOME=/opt/apache-maven
+ MAVEN_HOME=/opt/apache-maven
+ export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/apache-maven/bin
+ PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/apache-maven/bin
+ mvn --version
Apache Maven 3.6.2 (40f52333136460af0dc0d7232c0dc0bcf0d9e117; 2019-08-27T11:06:16-04:00)
Maven home: /opt/apache-maven
Java version: 1.8.0_232, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1062.9.1.el7.x86_64", arch: "amd64", family: "unix"
+ mvn -Dsonar.host.url=http://localhost:9000 clean test scoverage:report scala:compile sonar:sonar
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] example-mvn-multi-module                                           [pom]
[INFO] mvn-multi-module-module1                                           [jar]
[INFO] mvn-multi-module-module2                                           [jar]
[INFO] 
[INFO] ----------------< sonar-scala:example-mvn-multi-module >----------------
[INFO] Building example-mvn-multi-module 0.0.1-SNAPSHOT                   [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ example-mvn-multi-module ---
[INFO] Deleting /var/lib/jenkins/workspace/test-scala-module/target
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.4:prepare-agent (pre-test) @ example-mvn-multi-module ---
[INFO] argLine set to -javaagent:/home/jenkins/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/var/lib/jenkins/workspace/test-scala-module/target/jacoco.exec
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:pre-compile (instrument) @ example-mvn-multi-module ---
[INFO] Skipping SCoverage execution for project with packaging type 'pom'
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:add-source (scala-compile-first) @ example-mvn-multi-module ---
[INFO] Add Source directory: /var/lib/jenkins/workspace/test-scala-module/src/main/scala
[INFO] Add Test Source directory: /var/lib/jenkins/workspace/test-scala-module/src/test/scala
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:compile (scala-compile-first) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:post-compile (instrument) @ example-mvn-multi-module ---
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:testCompile (scala-test-compile) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scalatest-maven-plugin:2.0.0:test (test) @ example-mvn-multi-module ---
Discovery starting.
Discovery completed in 82 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 163 milliseconds.
Total number of tests run: 0
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.
[INFO] 
[INFO] >>> scoverage-maven-plugin:1.3.0:report (default-cli) > [scoverage]test @ example-mvn-multi-module >>>
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.4:prepare-agent (pre-test) @ example-mvn-multi-module ---
[INFO] argLine set to -javaagent:/home/jenkins/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/var/lib/jenkins/workspace/test-scala-module/target/jacoco.exec
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:pre-compile (instrument) @ example-mvn-multi-module ---
[INFO] Skipping SCoverage execution for project with packaging type 'pom'
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:pre-compile (default-cli) @ example-mvn-multi-module ---
[INFO] Skipping SCoverage execution for project with packaging type 'pom'
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:add-source (scala-compile-first) @ example-mvn-multi-module ---
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:compile (scala-compile-first) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:post-compile (instrument) @ example-mvn-multi-module ---
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:post-compile (default-cli) @ example-mvn-multi-module ---
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:testCompile (scala-test-compile) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] --- scalatest-maven-plugin:2.0.0:test (test) @ example-mvn-multi-module ---
Discovery starting.
Discovery completed in 70 milliseconds.
Run starting. Expected test count is: 0
DiscoverySuite:
Run completed in 157 milliseconds.
Total number of tests run: 0
Suites: completed 1, aborted 0
Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
No tests were executed.
[INFO] 
[INFO] <<< scoverage-maven-plugin:1.3.0:report (default-cli) < [scoverage]test @ example-mvn-multi-module <<<
[INFO] 
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:report (default-cli) @ example-mvn-multi-module ---
[INFO] Skipping SCoverage report generation
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:compile (default-cli) @ example-mvn-multi-module ---
[INFO] No sources to compile
[INFO] 
[INFO] ----------------< sonar-scala:mvn-multi-module-module1 >----------------
[INFO] Building mvn-multi-module-module1 0.0.1-SNAPSHOT                   [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mvn-multi-module-module1 ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.4:prepare-agent (pre-test) @ mvn-multi-module-module1 ---
[INFO] argLine set to -javaagent:/home/jenkins/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/var/lib/jenkins/workspace/test-scala-module/module1/target/jacoco.exec
[INFO] 
[INFO] --- scoverage-maven-plugin:1.3.0:pre-compile (instrument) @ mvn-multi-module-module1 ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mvn-multi-module-module1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/test-scala-module/module1/src/main/resources
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:add-source (scala-compile-first) @ mvn-multi-module-module1 ---
[INFO] Add Source directory: /var/lib/jenkins/workspace/test-scala-module/module1/src/main/scala
[INFO] Add Test Source directory: /var/lib/jenkins/workspace/test-scala-module/module1/src/test/scala
[INFO] 
[INFO] --- scala-maven-plugin:3.4.6:compile (scala-compile-first) @ mvn-multi-module-module1 ---
[INFO] /var/lib/jenkins/workspace/test-scala-module/module1/src/main/scala:-1: info: compiling
[INFO] Compiling 1 source files to /var/lib/jenkins/workspace/test-scala-module/module1/target/scoverage-classes at 1577964624178
[INFO] compiler plugin: BasicArtifact(com.sksamuel.scapegoat,scalac-scapegoat-plugin_2.12,1.3.9,null)
[ERROR] scalac error: /var/lib/jenkins/workspace/test-scala-module/module1/target/scoverage-classes does not exist or is not a directory
[INFO]   scalac -help  gives more information
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Skipping example-mvn-multi-module
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for example-mvn-multi-module 0.0.1-SNAPSHOT:
[INFO] 
[INFO] example-mvn-multi-module ........................... SUCCESS [  4.674 s]
[INFO] mvn-multi-module-module1 ........................... FAILURE [  0.681 s]
[INFO] mvn-multi-module-module2 ........................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.746 s
[INFO] Finished at: 2020-01-02T06:30:24-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.4.6:compile (scala-compile-first) on project mvn-multi-module-module1: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :mvn-multi-module-module1
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 1
Finished: FAILURE

We are having a 7 module scala project so want to know the dependencies needed and other parameters to analyse the scala code in sonarqube, your help is much appreciated.

Got the issue resolved Sorry for the trouble !

No problem, feel free to give me a shout if you need help with anything else.

Hopefully, the example is self-explanatory, but if you think it needs to be improved please let me know.

Thanks @mwz your examples are brilliant and keep up the great work, helps a lot of sonarqube novice like me !

Hi Michael, Well i ran into an issue while building our project :

[INFO] --- scala-maven-plugin:3.2.0:compile (scala-compile-first) @ models ---
[WARNING]  Expected all dependencies to require Scala version: 2.11.8
[WARNING] pro:models:6.0.0-SNAPSHOT requires scala version: 2.11.8
[WARNING]  com.github.nscala-time:nscala-time_2.11:1.0.0 requires scala version: 2.11.0
[WARNING] Multiple versions of scala libraries detected!
[INFO] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala:-1: info: compiling
[INFO] Compiling 13 source files to /var/lib/jenkins/workspace/sonar-analytics/models/target/scoverage-classes at 1578043925488
[INFO] compiler plugin: BasicArtifact(com.sksamuel.scapegoat,scalac-scapegoat-plugin_2.11,1.3.9,null)
[INFO] [info] [scapegoat] 118 activated inspections
[ERROR] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/Importance.scala:59: error: Floating type comparison
[ERROR]     if (sumW == 0.0)
[ERROR]              ^
[WARNING] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/KDE.scala:24: warning: Var could be val
[WARNING]     var waterline = 0.1
[WARNING]         ^
[ERROR] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/RelationStats.scala:97: error: Use of Option.get
[ERROR]     val existingMetric = if (existingMetrics.isDefined) existingMetrics.get else Stats(None, None, None, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0L)
[ERROR]                                                                         ^
[ERROR] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/RelationStats.scala:110: error: Use of Option.get
[ERROR]     minMaxCounts = if (existingMetric.min.isEmpty) minMaxCounts else minMaxCounts :+ existingMetric.min.get
[ERROR]                                                                                                         ^
[ERROR] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/RelationStats.scala:111: error: Use of Option.get
[ERROR]     minMaxCounts = if (existingMetric.max.isEmpty) minMaxCounts else minMaxCounts :+ existingMetric.max.get
[ERROR]                                                                                                         ^
[ERROR] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/RelationStats.scala:112: error: Use of Option.get
[ERROR]     minMaxCounts = if (existingMetric.secondHighest.isEmpty) minMaxCounts else minMaxCounts :+ existingMetric.secondHighest.get
[ERROR]                                                                                                                             ^
[ERROR] /var/lib/jenkins/workspace/sonar-analytics/models/src/main/scala/models/TimeUniformity.scala:22: error: Floating type comparison
[ERROR]       .filter(_ != 0.0)
[ERROR]                 ^
[ERROR] [error] [scapegoat] Analysis complete: 13 files - 6 errors 1 warns 10 infos
[WARNING] one warning found
[ERROR] 6 errors found
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Skipping Analytics Parent POM
[INFO] This project has been banned from the build due to previous failures.
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Ana Parent POM 6.0.0-SNAPSHOT ................ SUCCESS [  2.183 s]
[INFO] models 6.0.0-SNAPSHOT .............................. FAILURE [  5.629 s]
[INFO] ol 6.0.0-SNAPSHOT ............................. SKIPPED
[INFO] ks 6.0.0-SNAPSHOT ............................... SKIPPED
[INFO] rs 6.0.0-SNAPSHOT ........................... SKIPPED
[INFO] ye 6.0.0-SNAPSHOT ....................... SKIPPED
[INFO] job 6.0.0-SNAPSHOT ................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.141 s
[INFO] Finished at: 2020-01-03T04:32:10-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.0:compile (scala-compile-first) on project models: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR] 

How do i ignore those errors and proceed to analyse the next modules ? My pom file is similar to your multi-module pom file. Your help is much appreciated.

Thanks @mwz your examples are brilliant and keep up the great work, helps a lot of sonarqube novice like me !

Thanks, I'm glad you find those useful.

How do i ignore those errors and proceed to analyse the next modules ?

Those errors are coming from Scapegoat, so what you can do is you can locally downgrade those errors to warnings so that your project compiles without any errors using the -P:scapegoat:overrideLevels: compiler flag. See here and here for more details on how to use it. You can also use -P:scapegoat:overrideLevels:all=Warning to override the level of all inspections at once.

FYI, those issues will still show up in SonarQube with the right severity (i.e. major), so you don't need to worry that you're making them less important. You need to reduce the level of those in your project only so that you can compile it.

Thanks Michael for your valuable suggestion, i actual found that overrideLevels option and was doing it for all the 6 errors that were generated, thanks to that all command which will make our work simpler, Thanks a lot again ! :)

I did add that override line in args as shown below, but the results are the same, the rules still fails as errors.

<plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
                <!-- Scapegoat setup -->
                <configuration>
                    <args>
                        <arg>-P:scapegoat:dataDir:${project.build.directory}</arg>
                        <arg>-P:scapegoat:reports:xml</arg>
                        <arg>-P:scapegoat:overrideLevels:all=Warning</arg>
                    </args>
                    <compilerPlugins>
                        <compilerPlugin>
                            <groupId>com.sksamuel.scapegoat</groupId>
                            <artifactId>scalac-scapegoat-plugin_${scala.binary.version}</artifactId>
                            <version>${scapegoat.version}</version>
                        </compilerPlugin>
                    </compilerPlugins>
                </configuration>

I'm sorry to bother, is there anything i missed ?

Make sure you're using the latest version, this was released only recently in 1.4.0, scapegoat-scala/scapegoat@bc2f4fa.

@mwz Thanks Michael ! It worked, was using an older version. Appreciated !