local sonar analysis using a remote sonar server - maven

I am doing a sonar analysis from my machine using a sonar instance on a remote server.
Local machine: Window7, apache-maven-3.2.5
Remote sonarcube server: sonarcube Version 3.7.3
I am using below command from command prompt:
mvn sonar:sonar -Dsonar.jdbc.url=<jdbcurl> -Dsonar.host.url=<sonarserver url>
I have defined a sonar profile for running the same
Whe I run the said mvn command, then I am getting below error:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project builder-allmodules: Can not execute SonarQube analysis: Can not execute Findbugs: java.lang.RuntimeException: edu.umd.cs.findbugs.NoClassesFoundToAnalyzeException: No classes found to analyze in mymavenproject\target\classes *xyz.jar *F:\m2\repository\commons-io\commons-io\2.4\commons-io-2.4.jar *abc.jar *lmn.jar aaa.jarbbb.jar *ggg.jar
mymavenproject\target\classes: doesn't have any classes, instead, there is bundled jar at mymavenproject\target\ which contains all the classes
Also, another issue is that it is trying to analyze all the dependent jars also which should not be the case as I need sonar analysis for my project only
Can you let me know what I might be missing?

Because you've included FindBugs rules in your analysis profile, you're required to provide unbundled classes to the analysis.

Related

SonarQube not failing my local maven build, but is failing our CI build

The company I work for uses SonarQube as part of our CI build.
I have configured my settings.xml file according to: https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-maven/
I am pointing my local build at the same SonarQube server that is used by our CI build.
My build fails on the CI server as a result of the SQ analysis.
When I perform mvn sonar:sonar on my machine I am expecting a failed build with some helpful error messages. Instead, the build succeeds.
What am I doing wrong?

SonarQube analysis from maven and Jenkins have different results

I am using SonarQube version 6.7 for running analysis of Maven projects using the command mvn clean verify sonar:sonar from the project directory using command prompt and get the results. The sonar configurations in settings.xml for maven (v3.5.3) are added respectively.
In Jenkins (version 2.161), I have installed SonarQube Scanner for Jenkins (v2.8.1) plugin. The SonarQube Server configuration is configured as below.
In the Jenkins maven project, I have configured the post steps as below.
I have checked the Prepare SonarQube Scanner environment in the Build Environment section and the Build goal is -e clean verify sonar:sonar.
My issue is, when the SonarQube analysis for a maven project is triggered through command prompt using the command mvn clean verify sonar:sonar, I am getting the results as expected. But when the Jenkins job is triggered with the configurations above for the same maven project, the results are different and incorrect. What am I missing?
P.S- In the Post-build Actions, I can see the SonarQube analysis with maven is deprecated.
Thanks in advance.
You use different scanners. First you used SonarScanner for Maven (mvn sonar:sonar). Next you used Basi SonarScanner, which requires manual configuration of all options.
The best option to sole it is always use the same scanner. You have Maven project, so you can enable Prepare SonarQube Scanner environment in Build Environment, and next execute Sonar goal $SONAR_MAVEN_GOAL in Build.

sonar credential issue while running jenkins build

I am using Jenkins version 1.480.3 and Sonar version 3.4.1. I am executing Sonar analysis on my project using maven build option "sonar:sonar -PsonarJs" and below properties in jenkins:-
sonar.login=sonar
sonar.password=*****
sonar.host.connectTimeoutMs=300000
sonar.host.readTimeoutMs=600000
projectVersion=${projectVersion}
sonar.projectKey=abc
sonar.projectName=abc
sonar.projectVersion=${projectVersion}
sonar.sources=${MyPath)
sonar.branch=javascript
sonar.language=js
sonar.forceAnalysis=true
"sonar" is a local user created in Sonar.Upon firing the build in jenkins,sometimes my build fails with the following error:-
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.0:sonar (default-cli) on project vos-generic: Can not execute Sonar: Not authorized. Please check the properties sonar.login and sonar.password.
This is an intermittent error, sometimes the build fails with this error and sometimes it is successful.
I tried to resolve this error by creating a new local user "sonar1" in Sonar and adding it to the administrative group but got the same error again.
Any help is appreciated.Thanks in advance.

SonarQube - Jenkins - Maven - without running instance

I am running my analysis with Maven, triggered by a Jenkins job. As a DBMS i am using MySQL thats running on the same server as Jenkins does but my sonar instance is running on my local machine (connected to the MySQL DB). I don't want to run it on the server, yet. I would prefer to not run it at all for the time being.
Is it possible to run the analysis without a running sonar instance? Why do I have to configure the server URL (the login too) in both, the Jenkins plugin and the pom.xml?
The described architecture on SonarQube Platform Overview indicates that the analyser and server are not directly connected (only via DB).
When i try to run the analysis from Jenkins with no Server URI the build process is throwing the following message:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.2:sonar (default-cli) on project xxx: SonarQube server can not be reached at http://localhost:9000. Please check the parameter 'sonar.host.url'. Connection refused -> [Help 1]
Thats exactly what i expected, he is trying to connect to the SonarQube instance that i did not want to run.
You don't have to configure the URL to Sonar in the POM if you are using the Sonar plugin to push results to Sonar.
Sonar 'instance' you are referring to is for you to visually see the post code analysis result. If you don't have the Sonar UI web application installed, code analysis is still run by Maven either through Jenkins or your IDE or in the command prompt/shell.

Maven with sonar authentication

I am running maven with sonar. Since I activated authentication on sonar for security purposes, since then I got the following error:
[ERROR] Can´t access to Sonar or project doesn't exist on Sonar instance. HTTP KO to http://localhost:9000/api/resources?resource=com.myproject.soft:soft&depth=0&format=xml
java.io.IOException: Can´t access to Sonar or project doesn't exist on Sonar instance.
at org.sonar.report.pdf.util.SonarAccess.getUrlAsDocument(SonarAccess.java:132)
at org.sonar.report.pdf.entity.Project.initializeProject(Project.java:98)
according to http://docs.sonarqube.org/display/SONAR/Analyzing+with+Maven I should use the following parameters:
-Dsonar.login=login -Dsonar.password=password
Those settings are not working for me.
The full command I am using is:
mvn install sonar:sonar -Dsonar.login=login -Dsonar.password=password
This is a limitation of the PDF Report Plugin that is developed by Klicap:
http://jira.codehaus.org/browse/SONARPLUGINS-1510
If you remove this plugin, then everything should be back to normal.
We have the same problem and resolved it by adding some credentials. Tested on Sonar 3.7 and Sonar PDF Plugin 1.3
In eclipse put this as your maven Goals:
org.codehaus.sonar-plugins.pdf-report:maven-pdfreport-plugin:1.3:generate -Dsonar.host.url=http://localhost:9000 -Dreport.type=executive -Dsonar.pdf.username=admin -Dsonar.pdf.password=admin

Resources