Properties from properties file ignored with SonarQube Scanner 4.0.0.1744

Hello,
I am evaluating the Enterprise version of SonarQube v7.9.1
My company is most interested in “C Family” analysis.
I used the wrapper to generate the directory “sonar_wrapper_outdir”, but attempts to scan the results always fails.
My properties file looks like this:

sonar.projectKey=com.myco.myproj
sonar.projectName=myproj
sonar.projectVersion=1.0
sonar.sources=.
sonar.cfamily.build-wrapper-output=sonar_wrapper_outdir
sonar.sourceEncoding=UTF-8

My scanner command looks like this:
sonar-scanner.bat -X -Dsonar.host.url=tmpsonar:9000 -Dsonar.projectkey=com.myco.myproj -Dsonar.host.url=http://tmpsonar:9000 -Dproject.settings=.\myproj_Sonar.Properties

The output looks like this–except that I performed some global replacements to obscure anything specific to my company. I also shortened it a bit by inserting “…etc…” in a few places. Note in the output that the scanner acknowledges the existence of my “Project root configuration file”, but does not use its settings (note the final line of the output which complains that sonar.projectKey is “Unknown” even though it is set in my properties file).
12:24:38.733 INFO: Scanner configuration file: C:\ExperimentalJenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\SonarQube-Scanner-Via-Maven-Central\bin…\conf\sonar-scanner.properties
12:24:38.743 INFO: Project root configuration file: D:\repos\myproj-Developer\subd1\subd2\subd3\subd4\subd5.\myproj_Sonar.Properties
12:24:38.793 INFO: SonarQube Scanner 4.0.0.1744
12:24:38.793 INFO: Java 11.0.4 Oracle Corporation (64-bit)
12:24:38.793 INFO: Windows Server 2012 R2 6.3 amd64
12:24:38.995 DEBUG: keyStore is :
12:24:38.995 DEBUG: keyStore type is : pkcs12
12:24:38.995 DEBUG: keyStore provider is :
12:24:38.996 DEBUG: init keystore
12:24:38.996 DEBUG: init keymanager of type SunX509
12:24:39.334 DEBUG: Create: C:\Users\TheBuilder.sonar\cache
12:24:39.335 INFO: User cache: C:\Users\TheBuilder.sonar\cache
12:24:39.335 DEBUG: Create: C:\Users\TheBuilder.sonar\cache_tmp
12:24:39.339 DEBUG: Extract sonar-scanner-api-batch in temp…
12:24:39.345 DEBUG: Get bootstrap index…
12:24:39.346 DEBUG: Download: http://tmpsonar:9000/batch/index
12:24:39.429 DEBUG: Get bootstrap completed
12:24:39.436 DEBUG: Create isolated classloader…
12:24:39.450 DEBUG: Start temp cleaning…
12:24:39.482 DEBUG: Temp cleaning done
12:24:39.482 DEBUG: Execution getVersion
12:24:39.501 INFO: SonarQube server 7.9.1
12:24:39.501 INFO: Default locale: “en_US”, source code encoding: “windows-1252” (analysis is platform dependent)
12:24:39.503 DEBUG: Work directory: D:\repos\myproj-Developer\subd1\subd2\subd3\subd4\subd5.scannerwork
12:24:39.504 DEBUG: Execution execute
12:24:40.029 DEBUG: Enterprise 7.9.1.27448
12:24:40.208 INFO: Load global settings
12:24:40.265 DEBUG: GET 200 http://tmpsonar:9000/api/settings/values.protobuf | time=53ms
12:24:40.334 INFO: Load global settings (done) | time=126ms
12:24:40.344 INFO: Server id: A7EE8CF2-AWskbYe-bAlVzurgyKKJ
12:24:40.370 INFO: User cache: C:\Users\TheBuilder.sonar\cache
12:24:40.375 INFO: Load/download plugins
12:24:40.375 INFO: Load plugins index
12:24:40.385 DEBUG: GET 200 http://tmpsonar:9000/api/plugins/installed | time=10ms
12:24:40.456 INFO: Load plugins index (done) | time=81ms
12:24:40.829 INFO: Load/download plugins (done) | time=455ms
12:24:41.169 DEBUG: Plugins:
12:24:41.170 DEBUG: * Cobertura 2.0 (cobertura)
12:24:41.170 DEBUG: * SonarCSS 1.1.1.1010 (cssfamily)
…etc…
12:24:41.172 DEBUG: * SonarCFamily 6.3.0.11371 (cpp)
…etc…
12:24:41.174 DEBUG: * Vulnerability Rules for PHP 7.9.0.5105 (securityphpfrontend)
12:24:41.219 INFO: Loaded core extensions: developer-scanner
12:24:41.274 DEBUG: Installed core extension: developer-scanner
12:24:42.305 INFO: Process project properties
12:24:42.315 INFO: ------------------------------------------------------------------------
12:24:42.315 INFO: EXECUTION FAILURE
12:24:42.315 INFO: ------------------------------------------------------------------------
12:24:42.316 INFO: Total time: 3.636s
12:24:42.355 INFO: Final Memory: 5M/27M
12:24:42.355 INFO: ------------------------------------------------------------------------
12:24:42.355 ERROR: Error during SonarQube Scanner execution
java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:678)
at org.sonar.core.platform.ComponentContainer.getComponentByType(ComponentContainer.java:281)
…etc…
at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.fs.internal.DefaultInputProject
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
…etc…
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
… 22 more
Caused by: java.lang.IllegalStateException: Unable to load component class org.sonar.api.batch.bootstrap.ProjectReactor
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:65)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:632)
…etc…
at org.picocontainer.DefaultPicoContainer.getInstance(DefaultPicoContainer.java:699)
at org.picocontainer.DefaultPicoContainer.getComponent(DefaultPicoContainer.java:647)
at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:63)
… 36 more
Caused by: You must define the following mandatory properties for ‘Unknown’: sonar.projectKey

What am I doing wrong?

It looks like a problem with installed plugins or version of the SonarScanner. Use the latest version of SonarScanner and check if your all your plugins are compatible with your server version :wink:

Thank you for your reply Adam.
I double checked that all plugins are up-to-date. SonarCFamily 6.3(build 11371).
The scanner is the most current available, 4.0.0.1744-windows.
The problem persists.

I noticed that there is a sonar-scanner-debug.bat, so I tried executing that instead of the sonar-scanner.bat, but it seems to hang here:
Listening for transport dt_socket at address: 8000

Hi,

What catches my eye in this:

Is “-Dproject.settings=…”. As far as I know, this has never been a recognized property. The dead giveaway here is that it doesn’t start with sonar.. :slight_smile: That’s probably why you’re having to specify project key on the command line; your project properties aren’t being read.

Also, since your analysis logs show that your global settings are being picked up, there ought to be no need to specify the the host URL on the command line.

I recommend you move your properties file to the standard name/location: sonar-project.properties in the project root, and try reanalyzing with a simpler command line: sonar-scanner.bat.

 
HTH,
Ann

Thank you Ann.

Prompting me to move things to a more standard location may have been the thing that helped most.
Previously, my properties file was in a subdirectory of the Git repository–close to the VStudio solutions file (i.e., it was on D:\repos\myproj-Developer\subd1\subd2\subd3\subd4\subd5.\myproj_Sonar.Properties).

I moved myproj_Sonar.Properties to D:\repos\myproj-Developer\sonar-project.properties (i.e., to the standard name at the root of the repo) and the scan succeeded with:
sonar-scanner.bat -X -Dsonar.host.url=http://tmpsonar:9000

I’ll also note that the scan succeed with a properties file using the non-default name. So, after renaming sonar-project.properties to myproj_Sonar.Properties (still at the root of the repo), the scan succeed with:
sonar-scanner.bat -X -Dsonar.host.url=http://tmpsonar:9000 -Dproject.settings=myproj_Sonar.Properties

The -Dproject.settings property is used by the “SonarQube Scanner for Jenkins” plugin. That’s where I saw its usage.

It’s odd to me that I needed to run the scanner from the root of the Git repository, but, for now, I’ll accept that and move on. I’m happy to be making some progress.

Hi,

I’m glad you got this working. Just for the record, I want to point out that normally your sonar.host.url would be configured in the scanner’s own global configuration file, eliminating the need to specify it on the command line.

 
:slight_smile:
Ann