Possible False Positive Error while running sonarqube scanner

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube Version: Version 8.4.1 (build 35646)
    Jenkins Version : [Jenkins 2.235.3]

  • what are you trying to achieve
    I’m trying to use SonarQube scanner via Jenkins but getting an error as duplicate key (details below). I have not added any duplicate key anywhere. I configured this project for the first time.

  • what have you tried so far to achieve this
    I’ve tried to reconfigure the project and re-create the project in SonarQube so far. Any pointers, hints would be greatly appreciated.

Please find the stack trace below :

    [INFO] 
    [INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) @ app-parent ---
    [INFO] User cache: /var/jenkins_home/.sonar/cache
    [INFO] SonarQube version: 8.4.1
    [INFO] Default locale: "en_US", source code encoding: "UTF-8"
    [WARNING] SonarScanner will require Java 11 to run starting in SonarQube 8.x
    [INFO] Load global settings
    [INFO] Load global settings (done) | time=167ms
    [INFO] Server id: BF94B2F1-AXOmQm6qFeHum7EXs-HK
    [INFO] User cache: /var/jenkins_home/.sonar/cache
    [INFO] Load/download plugins
    [INFO] Load plugins index
    [INFO] Load plugins index (done) | time=134ms
    [INFO] Load/download plugins (done) | time=300ms
    [INFO] Loaded core extensions: developer-scanner
    [INFO] Process project properties
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary for app-services 1.0.0-SNAPSHOT:
    [INFO] 
    [INFO] app-services ................................... FAILURE [ 30.966 s]
    [INFO] commons ............................................ SKIPPED
    [INFO] app ................................................ SKIPPED
    [INFO] docgen ............................... SKIPPED
    [INFO] app-test-report .................................... SKIPPED
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  32.486 s
    [INFO] Finished at: 2020-08-06T08:14:28Z
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project app-parent: Project 'APP_services' can't have 2 modules with the following key: APP_services -> [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
    [Pipeline] }
    WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
    [Pipeline] // withSonarQubeEnv
    [Pipeline] }
    [Pipeline] // stage
    [Pipeline] }
    [Pipeline] // node
    [Pipeline] End of Pipeline
    [Bitbucket] Notifying commit build result
    [Bitbucket] Build result notified
    ERROR: script returned exit code 1
    Finished: FAILURE

Hello, Are you defining project or modules keys as a parameter? For example, do you define somewhere sonar.projectKey?

Hi Yes,
It’s defined as a property in parent pom.xml
e.g.

        <mapstruct.version>1.3.1.Final</mapstruct.version>
        <lombok.version>1.18.12</lombok.version>
        <spring-boot-maven-plugin.commons.folder>${project.basedir}/commons/target/classes
        </spring-boot-maven-plugin.commons.folder>
        <maven.surefire.plugin.version>3.0.0-M3</maven.surefire.plugin.version>
        <sonar.projectKey>APP_services</sonar.projectKey>
    </properties>

The property sonar.projectKey is probably being inherited by all modules, resulting in duplicated keys for the modules.
Try adding <sonar.moduleKey>${artifactId}</sonar.moduleKey>

As an alternative, define sonar.projectKey in the command line or using a sonar properties file.

The property sonar.projectKey is probably being inherited by all modules, resulting in duplicated keys for the modules

That explains!!

Thanks a lot, that was an insightful answer! this helped resolve the issue :slightly_smiling_face:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.