Exclude classes with #Data notation from Jacoco plugin analysis in Jenkins - jenkins

I have a project in Jenkins which I want to get its code coverage using Jacoco Code Coverage Plugin of Jenkins.
There are some classes in my source code with #Data notation which should be excluded from Jacoco analysis for some reason.
All include/exclude examples in the internet are performing at class/folder level directly; none of them are pointing to an attribute of the class. Is there any way to do so? Any solution with Jenkins plugins (not only Jacoco) is acceptable.

Place a file "lombok.config" in the root of your project with the configuration addLombokGeneratedAnnotation. This will be automatically recognized by JaCoCo 0.8.0 onwards.
# Root of your project, in a default Maven-project, would contain pom.xml
$ cat lombok.config
config.stopBubbling = true
lombok.addLombokGeneratedAnnotation = true

Related

Testing Jenkins "Code Coverage API Plugin"

I am new to Jenkins, I have installed "Code Coverage API Plugin" in Jenkins, now want to test it.
I am trying to do steps from this page https://plugins.jenkins.io/code-coverage-api/.
But I did not understand where to put XML files from points 1 and 2.
Can anybody help me, please?
The tags present in the images are the plugins that will be added in the pom.xml of the application. By running mvn clean package cobertura will generate a report based on the formats provided, xml or html.
If the code is checked out to the job and after running "mvn clean package" cobertura report will be generated under project workspace target/site/cobertura
The xml path is provided to code coverage api to provide the graphical representation.
Jacaco is preferred for java versions >=8 whereas cobertura doesn't cover for java8 based functionalities.

Generating code coverage and reports for all modules using Jenkins

We have an instant app project that is instrumented using jacaco. We run these jobs and report on the coverage using the jenkins coverage reporting plugin.
Our reports only show coverage reports for the base module and not the feature modules.
How do we resolve this? Thank you!
After reviewing the jacoco plugin for Jenkins I realized I needed to add the other modules details to the various fields:
Path to exec files (e.g.: /target/.exec, **/jacoco.exec):
Example:
base/build/jacoco/*.exec, feature-1/build/jacoco/*.exec
Path to class directories (e.g.: **/target/classDir, **/classes)
Example:
base/build/intermediates/classes/debug, feature-1/build/intermediates/classes/debug

How do I analyze Groovy code with Sonarlint for IntelliJ?

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.

switching from sonar-runner 2.3 to 2.4 results in error on analysis

I have a multi module project set up for sonar analysis using way #2 from Analyzing with SonarQube Runner.
The only difference is that I dont use a global sonar-project.properties file.
The global properties are defined in jenkins in the sonar runner build step.
This works perfectly fine with Sonar Runner 2.3.
As soon as I switch from 2.3 to Sonar Runner 2.4 this fails with the error that the mandatory sonar.sources property is not defined.
I have tried setting it in my global properties to sonar.sources=src but then sonar can't analyze a module that doesn't use src as source folder.
It looks to me like Sonar Runner 2.4 doesn't use the module's sonar-project properties anymore.
Or is there a way to tell Sonar Runner 2.4 to use the module's sonar-project.properties file?
The two supported layout when using SQ Runner are:
put all properties of all modules in root sonar-project.properties file
put each module properties in its own sonar-project.properties in addition to the root sonar-project.properties
It is also possible to add properties via command line (this is what you do when you define properties in SQ Runner build step).
Your attempt to not have a root sonar-project.properties but having individual sonar-project.properties files in sub modules was not identified as a supported use case. So I'm not very surprised it is no more supported (it was likely a side effect).
See http://docs.sonarqube.org/display/SONAR/Analyzing+with+SonarQube+Runner#AnalyzingwithSonarQubeRunner-Multi-moduleProject

Is it possible to run Sonar plugin on Jenkins without any build process?

I would like to run Sonar plugin on Jenkins without any build process (my intent was to integrate Sonar analysis within Jenkins and take advantage of the subversion plugins and configurations we already had on there).
I do not want to run the build process since that would take up unnecessary time; I would only like to have a Jenkins job dedicated for Sonar analysis.
You can do that. You have to triggering the analysis with the SonarQube Runner.
Go to the Build section, click on Add build step and choose Invoke Standalone Sonar Analysis
Configure the SonarQube analysis. You can either point to an existing sonar-project.properties file or set the analysis properties directly in the Project properties field
When you analyse with SonarQube Runner , then you should give the following mandatory properties:
sonar.projectKey=my:project
sonar.projectName=My project
sonar.projectVersion=1.0
# Path to the parent source code directory.
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# Since SonarQube 4.2, this property is optional. If not set, SonarQube starts looking for source code
# from the directory containing the sonar-project.properties file.
sonar.sources=src
In this case you may miss some rule violations (like FindBugs), because .class files are not provided. You have to build the project manually and set the sonar.binaries property to your class files. If you never want to build the project, then you can use the SourceMeter plugin for SonarQube too. It only needs the source files, but can produce more metrics and issues if you needed.

Resources