Sonar Scanner with Docker image finds no source files

625 Views Asked by At

I run a Sonar analysis, using sonar-scanner installed on my workstation:

sonar-scanner -Dsonar.host.url=<SONARQUBE_URL> -Dsonar.login=<TOKEN> -Dsonar.projectKey=<SOME_KEY> -Dsonar.java.binaries=target/classes

Everything runs fine. In particuler, the scanner finds 30 source files to analyse.

I run the same Sonar analysis, using the Docker sonar-scanner-cli image:

(winpty) docker run --rm -e SONAR_HOST_URL=<SONARQUBE_URL> -e SONAR_TOKEN=<TOKEN> -e SONAR_SCANNER_OPTS="-Dsonar.projectKey=<SOME_KEY>  -Dsonar.java.binaries=target/classes" -v `pwd`:/usr/src sonarsource/sonar-scanner-cli:4.8.0

It runs smoothly, but it does not detect any source file. Does anybody have a clue?

I added -Dsonar.sources=. to SONAR_SCANNER_OPTS, to no avail.

I replaced `pwd` with /c/Projects/my_project, to no avail.

Thanks in advance.

1

There are 1 best solutions below

0
Ivan dal Bosco On

The solution was to add a slash in front of `pwd`, that is, -v /`pwd`:/usr/src instead of -v `pwd`:/usr/src. Therefore the correct command is

(winpty) docker run --rm -e SONAR_HOST_URL=<SONARQUBE_URL> -e SONAR_TOKEN=<TOKEN> -e SONAR_SCANNER_OPTS="-Dsonar.projectKey=<SOME_KEY>  -Dsonar.java.binaries=target/classes" -v /`pwd`:/usr/src sonarsource/sonar-scanner-cli:4.8.0