0
votes

Gradle spring boot code analysis using SonarQube via Jenkins throws error.

I have at the root of the Gradle spring boot project my sonar-project.properties file with the following details

sonar.projectKey=some-project-key
sonar.projectName=some-project-name
sonar.projectVersion=1.0
sonar.sources=src/main/java/
sonar.exclusions=./src/main/resources/**
sonar.language=java
sonar.java.sources=1.8
sonar.java.binaries=build/classes/java/main

In Jenkins under "Global Tool Configuration" SonarQube Scanner is configured as

Name: SonarScanner
Install Automatically is checked
Install from Maven Central: SonarQube Scanner 3.0.3.778 

In the Jenkinsfile the stage is defined as

        stage('SonarQube') {
            environment {
                scannerHome = tool 'SonarScanner'
            }
            steps {
                withSonarQubeEnv('sonarqube') {
                    sh "${scannerHome}/bin/sonar-scanner"
                }
                timeout(time: 10, unit: 'MINUTES') {
                    waitForQualityGate abortPipeline: true
                }
            }
        }

When the job is run I get the following error

INFO: JavaClasspath initialization
ERROR: Invalid value for sonar.java.binaries
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 5.890s
INFO: Final Memory: 48M/120M
INFO: ------------------------------------------------------------------------
ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: No files nor directories matching 'build/classes/java/main/**'

Apparently sonar.java.binaries property is causing the problem.

I have experimented with following values one by one for sonar.java.binaries property. Nothing works and every time I get the same error.

build//classes//java//main
build/classes/java/main
build/classes
*//build//classes//java//main//**
//build//classes//java//main//**
build//classes//java//main//**
build/classes/java/main/**

I am at my wit's end. I would appreciate if somebody can help me out.

1
Could you add a list of files/directories stored in build/classes directory?agabrys

1 Answers

0
votes

I have manged to solve this issue. I had to define in sonar-project.properties, property value as follows.

sonar.java.binaries=build/libs

And Jenkins job was able to communicate with SonarQube server and publish the report.