SonarQube version: 4.5.1
Sonar Ant task: 2.2
We have configured the sonar build using ANT; Currently we are facing below errors,
WARN: Coverage information was not collected. Perhaps you forget to
include debug information into compiled classes
WARN: File '/aa/bb/cc/abc.xml' is ignored. It is not located in the
module base dir '/a/b/c/d'
Java byte code scan WARN: class '/a/b/c/d/e/f' is not accessible
through classLoader
[jacoco:report] classes in bundle 'project123'do not match with
execution data. For report generation the same class files must be
used at runtime
[jacoco:report] Execution data for class 'com/tttt/xyz/aaa12' does
not match
[jacoco:report] To enable source code annotation class files for
bundle 'project123' have to be compiled with debug information
Note:
All classes are compiled including debug information i.e. <javac debug="true" />
Our objective is to
Generate JaCoCo report
Display it on SonarQube dashboard (assume, Unit test coverage widget will display the coverage information?)
Not sure about the issue, hence need expert assistance.
Related
The Sonarlint plugin for IntelliJ does analysis on our Java code, but it won't analyze Groovy code in the same project.
We have a Grails project which works with sonar-runner on the command line. When I install the IntelliJ IDEA Sonarlint plugin, the plugin doesn't seem to pick up the settings from our command line config, and it doesn't show the warning highlights for issues like it does for the Java files in the editor.
Our project uses the "code-coverage" Grails plugin to generate an XML coverage report, then the sonar runner (command line tool) pulls in the metrics. In sonar-project.properties, we set:
# Project key within sonar
sonar.projectKey=com.mycompany:myapp
sonar.projectName=My Grails Project
sonar.projectVersion=1.0
# Source directories to analyze
sonar.sources=src/groovy, grails-app/domain, grails-app/services, grails-app/controllers, grails-app/utils, grails-app/taglib, grails-app/views
# Set language for the project to be Groovy
sonar.language=grvy
# Path to the Cobertura XML report
sonar.grvy.coveragePlugin=cobertura
sonar.groovy.cobertura.reportPath=target/test-reports/cobertura/coverage.xml
sonar.jdbc.username=...
sonar.jdbc.password=...
sonar.host.url=http://sonar.mycompany.com
sonar.jdbc.url=...
sonar.jdbc.driverClassName=...
The properties file has JDBC settings, the coverage report path, etc.
SonarLint is a different product than SonarQube (even if there are some links). For example SonarLint doesn't know what is sonar-project.properties. The purpose is to integrate with IntelliJ, not with some external configuration.
Regarding Groovy support, this is not planned since we don't have any Groovy analyzer (the SonarQube plugin for Groovy is simply reusing codenarc reports AFAIK). If you want to run Codenarc in IntelliJ, there is already a dedicated plugin for that.
I have created jacoco.exec file by setting -javaagent as jvm option in my server startup script. Now I want to generate coverage report using the coverage exec file.
I've gone though all Jacoco report generation options (maven, ant, API etc..) However all these options required to have source class files. I'm trying to generate coverage for set of jar files where as sources files are not available. In that case, is there a workaround to achieve coverage generation.
Yes, you can generate report without source code, I also generated the exec file by setting the option in server startup script, then I got the exec file and generated the report in eclipse using eclemma code coverage plugin.
I am doing a Sonar analysis of my project on a Jenkins Server using SonarRunner within an ant build. Unfortunately, the Analysis crashes with the following lines:
[sonar:sonar] 11:29:57.008 INFO - Execute Findbugs 2.0.3...
[sonar:sonar] 11:29:58.217 DEBUG - Release semaphore on project : org.sonar.api.resources.Project#5c1f0a26[id=3998,key=<key>,qualifier=TRK], with key batch-<key-batch>
[sonar:sonar] 11:29:58.247 DEBUG - To prevent a memory leak, the JDBC Driver [com.mysql.jdbc.Driver] has been forcibly deregistered
BUILD FAILED
<Path>: The following error occurred while executing this line:
<Path>: org.sonar.runner.impl.RunnerException: Unable to execute Sonar
I have other projects running on the same server, which have no problem performing this analysis (and where the analysis is triggered exactly the same way). As you can see, I changed the log level to DEBUG, but, nevertheless, I get no stack trace and I am not able to find useful information in the logs of Jenkins or Sonar.
One other thing, I tried, was to increase the Heap space (with -Xmx) for this ant task in Jenkins but that didn't help either.
Are there any other settings I can take to get useful information or does somebody know about this problem?
Thanks!
Some more information could be useful. E.g.: what SonarQube and SonarRunner versions are you running.
Findbugs is one of the few analyzing plugins that need .class data for analyzing the project. So if you have not changed the directory within your build.xml the ant task may search within the default output folder location.
Please make sure your .class files are located here. To make them appear here you have to compile them before of course
I agree that this question is asked many a times by many people and many solutions are already been provided. However, after referring to umpteen links, not being able to display the Emma report in Sonar is driving me crazy. Below is a description of what I am trying to do.
My java project is a multi module maven project. We are using EMMA as the code coverage tool and Jenkins to build the project, Sonar to analyze the code and configured Sonar for our build job using the Jenkins sonar plugin. Up to this point, the story is great. The problem comes when I try to reuse the reports generated by Emma during Sonar analysis. There is no apparent error in the Sonar analysis logs during the build, however, in Sonar project dashboard the coverage report is 0%. Below is configuration data that I provide in the Sonar configuration section of my Jenkins build job.
-Dsonar.core.codeCoveragePlugin=emma
-Dsonar.emma.reportPath=/target
-Dsonar.dynamicAnalysis=reuseReports
-Dsonar.surefire.reportsPath=/target/surefire-reports
Sonar Version : 3.0
Emma plugin versions:
emma-maven-plugin : 1.0-alpha-2
Sonar Emma Plugin :1.0.1
emma : 2.0.5312
The Maven build generates the coverage.em files in the individual modules' target folder. No coverage.ec file is generated. Is it mandatory to have both coverage.ec and coverage.em files for Sonar?
The coverage.es,html,txt,xml files are generated in the project build directory/emma folder
The Sonar analysis logs for a module looks like below.
[INFO] [15:06:02.829] Sensor org.sonar.plugins.emma.EmmaSensor#bfc33...
[WARN] [15:06:02.844] Resource will be ignored in next Sonar versions, index is locked: com.mycompany.mypackage.tests.util.Activator
[INFO] [15:06:02.876] Sensor org.sonar.plugins.emma.EmmaSensor#bfc33 done: 47 ms
The above logs make me think that Sonar is indeed doing something with the generated Emma reports, but not displaying anything on the Sonar project dashboard.
Please let me know where I may be going wrong or what additional thing needs to be done to get this working.
I think this thread might me useful. http://sonar.15.n6.nabble.com/Receiving-quot-index-is-locked-quot-warning-when-Emma-sensor-runs-td4676490.html
It describes the same problem and gives you some workarounds
my setup is:
Jenkins 1.448
Sonar 2.13
Jenkins Sonar Plugin 1.72
a MySql database for Sonar
I have the following project:
Eclipse Plugin Project
using Maven
multiple modules (parent maven project, source plugin project, test fragment project)
a simple JUnit test testing a class of the source plugin project
What the process is at the moment:
Jenkins checks out the parent project from SVN
Jenkins builds the project and its modules using Maven and Tycho
Jenkins uses Surefire to execute the tests and produce a report
Jenkins uses the Jenkins Sonar plugin to start mvn sonar:sonar to execute code analysis
Static code analysis is done on each module
JaCoCo fails
Sonar has static code analysis statistics available and test success percentage is shown.
The only thing that's missing is JaCoCo's code coverage...or maybe even Cobertura's code coverage.
I don't really care at this point, I just want one of these things to produce code coverage results.
Cobertura seems to be unable to produce results possibly because either
- it can't instrument the code
- it looks for the instrumented code at the wrong place
- it can't cope with Tycho or the separate source/test code setup
JaCoCo should be able to "watch" the code coverage on the fly, but its output is
[INFO] [17:44:04.708] Sensor JaCoCoSensor...
[INFO] [17:44:04.717] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testSource/target/jacoco.exec
[INFO] [17:44:04.854] Sensor JaCoCoSensor done: 146 ms
[INFO] [17:44:10.587] Sensor JaCoCoSensor...
[INFO] [17:44:10.587] Project coverage is set to 0% as no JaCoCo execution data has been dumped: /var/lib/jenkins/jobs/testPlugin/workspace/testTest/target/jacoco.exec
[INFO] [17:44:10.631] Sensor JaCoCoSensor done: 44 ms
[INFO] [17:44:12.402] Sensor JaCoCoSensor...
[INFO] [17:44:12.402] Project coverage is set to 0% as build output directory doesn't exists: /var/lib/jenkins/jobs/testPlugin/workspace/testParent/target/classes
[INFO] [17:44:12.402] Sensor JaCoCoSensor done: 0 ms
What am I doing wrong? Do I need to enable JaCoCo in my pom.xml somewhere? Do I need surefire? What do I need to do to use Cobertura?
I've found a page with an example tycho multi-module project (separate source and test projects). After copying some of the properties and configurations...
it seems that I now use a maven jacoco plugin to generate the jacoco code coverage report and then tell Sonar where to find the report and reuse it.
Why on earth is there next to no documentation for this? Or why is it so hard to find?
https://github.com/Godin/sonar-experiments/tree/master/jacoco-examples/tycho-example
You can have a look on the blog post I wrote few months ago : http://mdwhatever.free.fr/index.php/2011/09/quality-analysis-on-eclipse-plugins-with-tycho-sonar-jacoco-and-swtbot/
When the code is done being instrumented, surefire has to be ran on that specific code that the instrumentation generates. I've not used your setup, but your error seems very similar to what I got when I was getting Clover code coverage to work; I had to point surefire to run tests out of the directory that the compiled instrumented code was being stored in.
Also, I found specifying the -X option on the Maven command line to be invaluable as reading the logs of each plugin during a build shows you exactly where it's looking for whatever it's trying to find.
Edit:
Instrumented code will have to be compiled before surefire can run against it, so you'll want to point to the post-compilation directory and not the instrumented source itself.