9

I've configured everything to do a Sonar analysis on a Maven project. Everything is fine until I run sonar-runner :

     Max$ sonar-runner
     INFO: Scanner configuration file: /Users/Max/Documents/sonar-scanner-2.5/conf/sonar-runner.properties
     INFO: Project configuration file: NONE
     INFO: SonarQube Scanner 2.5
     INFO: Java 1.7.0_45 Oracle Corporation (64-bit)
     INFO: Mac OS X 10.10.3 x86_64
     INFO: User cache: /Users/Max/.sonar/cache
     INFO: Load global repositories
     INFO: Load global repositories (done) | time=143ms
     INFO: Property 'sonar.jdbc.url' is not supported any more. It will be ignored. There is no longer any DB connection to the SQ database.
     INFO: User cache: /Users/Max/.sonar/cache
     INFO: Load plugins index
     INFO: Load plugins index (done) | time=4ms
     INFO: Default locale: "fr_FR", source code encoding: "UTF-8" (analysis  is platform dependent)
     INFO: Process project properties
     INFO: ------------------------------------------------------------------------
     INFO: EXECUTION FAILURE
     INFO: ------------------------------------------------------------------------
     INFO: Total time: 1.631s
     INFO: Final Memory: 40M/194M
     INFO: ------------------------------------------------------------------------
     ERROR: Error during SonarQube Scanner execution
     ERROR: Unable to load component class org.sonar.batch.scan.ProjectLock
     ERROR: Caused by: Unable to load component class     org.sonar.api.batch.bootstrap.ProjectReactor
     ERROR: Caused by: You must define the following mandatory properties for 'Unknown': sonar.projectKey, sonar.projectName, sonar.projectVersion, sonar.sources
     ERROR: 
     ERROR: To see the full stack trace of the errors, re-run SonarQube  Scanner with the -e switch.
     ERROR: Re-run SonarQube Scanner using the -X switch to enable full debug logging.
  • I'm running sonar-runner inside my java project folder
  • I have put and configured the sonar-runner.properties in my java project

    sonar.projectKey=SeleniumMaven:sonar
    sonar.projectName=SeleniumMaven
    sonar.projectVersion=1.0
    sonar.sources=src
    sonar.sourceEncoding=UTF-8
    sonar.language=java
    

Any idea?

Daniel Serodio
  • 4,229
  • 5
  • 37
  • 33
user3568978
  • 111
  • 1
  • 1
  • 7
  • 3
    Why are you using Sonar Runner if you have a Maven project? Just use the Sonar Maven Plugin. – Tunaki Feb 10 '16 at 12:17
  • In my case it turned out I was calling the scanner from a wrong location. Don't forget the `dir` step if using Jenkins pipeline. – Georgii Ivankin Aug 02 '18 at 17:54

3 Answers3

7

I had the same problem and I realized my file name was incorrect: instead of "sonar-project.properties" I had it as "sonar-project.properties.properties".

I would try and change your file name to "sonar-project.properties" and try ...

Pratik
  • 201
  • 5
  • 13
  • In my case the file name had special character `mv sonar-project.properties̀ sonar-project.properties` – Ajitsen Feb 06 '19 at 10:52
  • brilliant!....in my case i had named it sonar-projects.properties – Kaushik J Feb 24 '22 at 17:30
  • Thank you!!, in my case, I had whitespace before the file name which was completely invisible when I saw your answer I was sure this isn’t the case until I realized the problem :O – Aya Salama Jul 12 '22 at 14:04
6

Try passing the values like this :

sonar-runner -Dsonar.projectKey=..... -Dsonar.projectName=...

if it works, it means the property file is somewhat ignored

If you look at the following message :

INFO: Scanner configuration file: /Users/Max/Documents/sonar-scanner-2.5/conf/sonar-runner.properties
INFO: Project configuration file: NONE

It seems like your project configuration file is indeed ignored

Hello_world
  • 303
  • 2
  • 11
  • 1
    Well thanks, it's working ! Don't know why my property file is ignored ! – user3568978 Feb 10 '16 at 12:19
  • Do you run the command from the project's root directory ? However, as stated by @Tunaki, you should use the sonar maven plugin if your project is maven based. This way you could attach the analysis to a maven phase etc.. – Hello_world Feb 10 '16 at 12:40
5

You need create a configuration file in the root directory of the project: sonar-project.properties

If a sonar-project.properties file cannot be created(or you won`t) in the root directory of the project, there are several alternatives:

  • The properties can be specified directly through the command line. Ex:

    sonar-scanner -Dsonar.projectKey=myproject -Dsonar.sources=src1

  • The property project.settings can be used to specify the path to the project configuration file (this option is incompatible with the project.home and sonar.projectBaseDir properties). Ex:

    sonar-scanner -Dproject.settings=../myproject.properties

The root folder of the project to analyze can be set through the sonar.projectBaseDir property since SonarQube Scanner 2.4 (was previously project.home). This folder must contain a sonar-project.properties file if the mandatory properties (like sonar.projectKey) are not specified on the command line.

Additional analysis parameters can be defined in this project configuration file or through command-line parameters.