Generating code coverage reports on Azure DevOps with Gradle 5.X - gradle

I'm trying to upgrade my project to Gradle 5.6.2. One of the tasks that I run on Azure DevOps is:
- task: Gradle#2
displayName: 'Test Project'
inputs:
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx7000m'
sonarQubeRunAnalysis: true
sonarQubeGradlePluginVersion: 2.6.2
testRunTitle: $(DISPLAY_NAME)
codeCoverageToolOption: JaCoCo
publishJUnitResults: true
testResultsFiles: '**/build/test-results/test/TEST-*.xml'
tasks: "test -Dtest.profile=unit --parallel"
After upgrading to Gradle 5.6.2 I get the following error when the code coverage reports are run:
Could not find method destination() for arguments [/home/vsts/work/1/s/batch/build/jacocoHtml] on Report html of type org.gradle.api.reporting.internal.TaskGeneratedSingleDirectoryReport
According to this answer, some changes were made to the reporting API in Gradle 5.X. Is the version of JaCoCo that's used on Azure Devops incompatible with Gradle 5.X? If so, is there anything I can do about this?

Some changes were made to the reporting API in Gradle 5.X, Is the version of JaCoCo that's used on Azure Devops incompatible with Gradle 5.X?
See this pull request: JaCoCo compatible with gradle 5.x. Last month, we raised a pull request to improve our Gradle task script since the feature has changed in Gradle 5.x(see this changes):
Also, the PR has been merged successfully. In one word, now, for our Gradle task, the Jacoco version is compatible with Gradle 5.x which has upgrade the new syntax.
To solve your issue, I suggest you'd better follow the solution which in the link you shared in question, to ensure the script of your build.gradle file is similar as the below format:
destination file("$xx/xxx/xx.xml")
Also, you can check this thread.

Related

Configuring the sonarqube gitlab plugin, preview mode

I am trying to configure the Gilab Sonar Plugin, so we can get sonar review comments in merge requests.
We have configured our gradle project, as per documentation and through gitlab-ci.yml, we call sonarqube task:
# Run sonar feature analysis
sonar_feature:
stage: sonar
only:
- /^BE-*/
tags:
- gitlab-runner-docker
script:
- ./gradlew sonarqube -Dsonar.analysis.mode=preview
-Dsonar.gitlab.project_id=${CI_PROJECT_PATH}
-Dsonar.gitlab.commit_sha=${CI_COMMIT_SHA}
-Dsonar.gitlab.ref_name=${CI_COMMIT_REF_NAME} -Dsonar.verbose=true
The 'sonarqube' task completes in gradle, but an 'external' job remains in running status, without completing . In Sonarqube itself, I don't see a new background task, so it seems analysis is not really occurring and it's a hanging/waiting mode.
Notes:
1. We don't see logging on the sonar_feature job, eventhough sonar.verbose=true.
What could be the issue?
I had the same problem when I had not configured sonar.gitlab.user_token.
Generate a User Token in GITLAB and add it to your sonar properties

Difference between gradle upload and gradle publish

I am testing pushing my artifacts to a Nexus maven repository. I am using gradle to do so.
What is the difference between gradle upload and gradle publish?
Currently gradle provides two publishing mechanisms. Original - shipped with java plugin - is described here and is based on a task of type Upload. This mechanism is going to be replaced by the - currently incubating - second mechanism that is separated from java plugin and also splitted into maven and ivy. This new mechanism is described here.
Also have a look at "Upgrading your build from Gradle 6.x to the latest": "Removal of the uploadArchives task: The uploadArchives task was used in combination with the legacy Ivy or Maven publishing mechanisms. It has been removed in Gradle 7. You should migrate to the maven-publish or ivy-publish plugin instead."

Uploading Spock/Groovy test results into Sonarqube

There was a known issue from 2014 that UnitTests written in Groovy cannot have their PASS/FAIL metrics uploaded into SonarQube.
http://sonarqube-archive.15.x6.nabble.com/Resource-not-found-for-Groovy-unit-tests-td5024669.html
Does anyone know if this issue is fixed? I am still have the issue with Sonar 6.1 using Spock unit tests and Gradle build system.
Any clue on the correct gradle sonar settings to make this happen?
The solution for us was to install the Groovy plugin in Sonarqube 6.1.
Once the plugin was installed, we could see the tests, with this command line:
./gradlew sonarqube -Dsonar.tests=src/test/groovy -Dsonar.junit.reportsPath=build/test-results/test/
We are using Spock as well (with Gradle, as you can see)

Jenkins jacoco plugin - Dashboard Reports are gone with Java8

Most of the projects that I'm working with used Gradle 1.6 upto 2.3 with Java7 and I'm using Jacoco for code coverage.
Jenkins version is: 1.565.3 and 1.618 (I have two instances)
Jenkins's Jacoco Plugin version: 1.0.12
Gradle version: 2.3
Gradle's Jacoco Plugin version: 0.7.2.201409121644
Now in Gradle, there's a jacoco plugin (which provides jacocoTestReport task) and in Jenkins there's a Jacoco plugin which reads the exec files generated by running various tests and shows the reports on the Jenkins job's dashboard.
These reports are not showing up now if I'm using Java 8 with Gradle 2.0 upto 2.3 versions. Jenkins jobs builds and runs the analysis on Jacoco successfully but the reports is gone.
Have you seen this issue?
If you see this, it shows Coverage is gone and with the latest build all what is there is RED / no coverage.
Main dashboard:
Jacoco Plugin report (if you click on the above report on the job):
NOTE:
I have valid .exec files which shows valid code coverage if I use Gradle's jacocoTestReport task to generate the coverage in HTML format but the Jacoco plugin dashboard reports are not showing anything (just shows the headers only with no data/no coverage at all).
Reports generated by jacocoTestReport and Jacoco plugin in Jenkins generated valid output when I'm using Java7.
Report generated by Gradle's jacocoTestReport task using the same .exec files shows that jacoco* .exec files that I have are valid.
I figured out the cause why code coverage is not showing for Java 8 projects.
It's due to the incompatible version of Jenkins's Jacoco Plugin which works only with Java7 in your Jenkins instance. Try updating Jacoco plugin in Jenkins it to the latest version (1.0.15+).
Support to Java 8 was provided with version 1.0.15. Release notes of Jacoco plugin
Version 1.0.15 (Jun 11, 2014)
• Fix [JENKINS-20440] Inspector problem
• Fix [JENKINS-22716] - Update to JaCoCo 0.7.x to support Java 8
• Fix #40 - Project Dashboard chart having data cut off
Hence, jacoco plugin needs to be upgraded in your Jenkins.
Also, see Version info/Release info here: https://wiki.jenkins-ci.org/display/JENKINS/JaCoCo+Plugin
You'd notice there's a warning message (at this time) which might be resolved in upcoming versions (in few days).
Unfortunately JaCoCo 0.7.5 breaks compatibility to previous binary formats of the jacoco.exec files, the JaCoCo plugin is currently based on JaCoCo 0.7.4, thus you cannot use this plugin with projects which already use JaCoCo 0.7.5 or newer, please stick to 0.7.4 or lower for now until the plugin is updated

SonarQube 4.4 upgrade can not show test coverage on dashboard

I upgraded my sonarqube from 4.1 to 4.4. as in the latest java plugin 2.4 you don't need to have a JaCoCo plugin. I have deleted the jacoco plugin, but now i can not see Tes coverage on sonar dashboard - it's blank. We use bamboo for CI tool and run sonar build from Bamboo. we run below maven command from bamboo build .
clean verify -Psonar sonar:sonar -U -fae -Dsonar.forceAnalysis=true
With latest versions of the SQ Java plugin, tests are no longer automatically executed. They must be executed prior to the SonarQube analysis and configured so that they produce reports that can be read by the SQ Java plugin.
Everything is explained on the Code Coverage by Unit Tests for Java Project documentation page.

Resources