How Do You Troubleshoot the sonar-scanner CLI Not Working?

Problem scenario
You run sonar-scanner from the command prompt, but you receive an error. The error looks like one of the following:

“Task ‘-x’ does not exist. Please use ‘list’ task to see all available tasks”

“You must define the folowing mandatory properties for ‘Unknown’: sonar.projectKey, sonar.sources”

What should you do to get sonar-scanner to work?

Solution
Run the sonar-scanner command from a local directory where you have sonar-project.properties.

 » Read more..

How Do You Get SonarQube to Use a New Database Connection and Change It from the Previous One It Was Working with?

Problem scenario
You try to start an old SonarQube instance but with a new database connection. In the web.log file you see a message like this: “Can not connect to database. Please check connectivity and settings.” What should you do?

Solution
Go to sonar.properties. Find the connection string for the new database. It should look something like this:

sonar.jdbc.url=jdbc:oracle://FQDN:1521:XE

The default port for Oracle databases is 1521.

 » Read more..

How Do You Get sonar-scanner to Work When You Seem to Have No Quality Profiles and Your Server Has No Internet Access?

Problem scenario
You run sonar-scanner, but it fails with an error such as this: “No quality profiles have been found, you probably don’t have any language plugin installed.”

You run sonar-scanner with the “-X” and see a Java stack trace like this: “Error during SonarQube Scanner execution java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.report.MetadataPublisher”

You log into the SonarQube web UI. You go to “Quality Profiles” but you see no profiles and no button or option to create one.

 » Read more..

How Do You Get around The AccessDeniedException Error with SonarQube?

Problem scenario
You are trying to set up SonarQube for the first time. You run this command:

bash /opt/sonarqube/bin/linux-x86-64/sonar.sh console

You see this error:

“jvm 1 | java.nio.file.AccessDeniedException: /opt/sonarqube/temp/conf/es/elasticsearch.yml”

What do you do?

Solution
Make sure that the user who is running the command has the ability to execute files in the /opt/sonarqube/ directory (or wherever the destination is that you are installing Sonarqube).

 » Read more..

How Do You Analyze Code with SonarQube?

Problem scenario
You want to utilize SonarQube to do some analysis of some code. What do you do?

Solution
Prerequisites
This assumes you have SonarQube and SonarQube Scanner (aka sonar-scanner) installed. If you need assistance with either of these, see this link to install SonarQube or this link to install sonar-scanner.

Procedures

  1. Place the source code file (e.g.,

 » Read more..

How Do You Troubleshoot the SonarScanner Error “java.lang.IllegalStateException: Failed to create lock in /opt/app/sonar-scanner/conf/…sonar_locak…DirectoryLock…”?

Problem scenario
You try to run sonarscanner from a command prompt.  But you get this message:

“java.lang.IllegalStateException: Failed to create lock in /opt/app/sonar-scanner/conf/…sonar_locak…DirectoryLock…”

What should you do?

Solution
Become a different user to run the sonarscanner command or use “sudo ” before your command.

 » Read more..

How Do You Get the sonar.sh Console to Actually Work When the Screen Says That “SonarQube is already running”?

Problem scenario
You stop SonarQube services from running.  You want to log into the web UI console to set things up.  You run this command:

sudo bash /opt/sonarqube/bin/linux-x86-64/sonar.sh console

But all you see is


Running SonarQube…
SonarQube is already running.

You never get a network service to listen on port 9000.  How do you use “sonar.sh console” to initially configure Sonar?

 » Read more..

How Do You Troubleshoot the SonarQube Service Not Working with a “vendor preset: disabled” Error?

Problem scenario
The SonarQube service failed to start.  

You see this message:

? sonar.service – SonarQube service
   Loaded: loaded (/etc/systemd/system/sonar.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Mon 2018-05-21 14:34:34 UTC; 12min ago

May 21 14:34:33 sonarserver systemd[1]: Started SonarQube service.
May 21 14:34:34 sonarserver systemd[1]: sonar.service holdoff time over, scheduling restart.
May 21 14:34:34 sonarserver systemd[1]: start request repeated too quickly for sonar.service
May 21 14:34:34 sonarserver systemd[1]: Failed to start SonarQube service.

 » Read more..

How Do You Troubleshoot the SonarQube Scanner Error “java.lang.IllegalStateException: Unable to load component class or.sonar.scanner.scan.ProjectLock”?

Problem scenario
You are trying to run SonarScanner, but you get an error about “java.lang.IllegalStateException: Unable to load component class or.sonar.scanner.scan.ProjectLock”.  What should you do?

Possible solution
Is there a sonar-project.properties file in the directory where you are running the above command?  Does your user have access to read the file?  Check these things first.

 » Read more..

How Do You Troubleshoot a “500 Error” with SonarQube?

Problem scenario
You try to run SonarScanner or do something with SonarQube.  You get a “500 Error” or some related internal server error.  What should you do?

Solution
Reinstall Java.  It is a dependency for SonarQube.  You can keep SonarQube installed and just stop the services while you uninstall and reinstall Java.  After you remove Java (and do research if you don’t know how), you can use this 

 » Read more..