Skip to content

SonarQube jobs are not reporting code coverage #6092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jzheaux opened this issue Nov 14, 2018 · 10 comments
Closed

SonarQube jobs are not reporting code coverage #6092

jzheaux opened this issue Nov 14, 2018 · 10 comments
Assignees
Labels
in: build An issue in the build

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Nov 14, 2018

We haven't seen code coverage on our SonarQube analyses for a while.

@jzheaux jzheaux added the in: build An issue in the build label Nov 14, 2018
@raphaelDL
Copy link
Contributor

I think I may have parts of the solution, will submit al PR tomorrow, midnight already but I needed to know what was going on with this
Local SonarQube

@raphaelDL
Copy link
Contributor

raphaelDL commented Nov 23, 2018

Hey!

I tried the next:

a) Edited build.gradle and added right after the buildscript section

plugins {
	id "org.sonarqube" version "2.6.2"
}

apply plugin: 'io.spring.convention.root'
apply plugin: 'jacoco'
apply plugin: "org.sonarqube"

b) Ran:

./gradlew clean jacocoTestReport sonarqube -PexcludeProjects='**/samples/**' -Dsonar.jacoco.reportPaths='**/build/jacoco/*.exec'

I tried it with a fresh new sonarqube container and so far it looks like it is working.

Q: I'm not sure if that plugin declaration is defined elsewhere, I couldn't find it :(
Is it transitive? if so, what version are we getting?

What do you think @jzheaux ???

PD: Happy thanksgiving day 🦃

@raphaelDL
Copy link
Contributor

raphaelDL commented Nov 23, 2018

Turns out the step a) is not needed, I just ran:

./gradlew clean jacocoTestReport sonarqube -PexcludeProjects='**/samples/**' -Dsonar.jacoco.reportPaths='**/build/jacoco/*.exec'

and got the coverage report shown again in a fresh new sonar container. Maybe what we were missing was telling sonar where the reports are located.

I think we just need to edit the command in the Sonar step.

As stated in build.gradle we need to explicitly call jacocoTestReport to get the report, otherwise it will not be generated.

My question is: what do we use wen calling the Sonar routine, Jenkinsfile or travis.yml?

Knowing this I think I can submit a PR

@jzheaux
Copy link
Contributor Author

jzheaux commented Nov 23, 2018

@raphaelDL wow, thanks for your extra research here! You are the man.

We use Jenkinsfile for the sonar routine.

Are you saying that when you run with ./gradlew clean sonarqube -PexcludeProjects='**/samples/**' you don't see code coverage in the Sonar report, but when you do ./gradlew clean jacocoTestReport sonarqube -PexcludeProjects='**/samples/**' -Dsonar.jacoco.reportPaths='**/build/jacoco/*.exec' then you do see code coverage in the report?

Makes sense, just want to make sure we are on the same page.

If so, then I think that is enough to submit a PR, yes.

raphaelDL added a commit to raphaelDL/spring-security that referenced this issue Nov 23, 2018
This commit ensures that jacocoTestReport task is called when running the Sonar stage.
Additionally, a variable is passed instructing Sonar where to find the test result data.

Fixes: spring-projectsgh-6092
@raphaelDL
Copy link
Contributor

Absolutely ¡, let's try it

jzheaux pushed a commit that referenced this issue Nov 26, 2018
This commit ensures that jacocoTestReport task is called when running the Sonar stage.
Additionally, a variable is passed instructing Sonar where to find the test result data.

Fixes: gh-6092
jzheaux pushed a commit that referenced this issue Nov 26, 2018
This commit ensures that jacocoTestReport task is called when running the Sonar stage.
Additionally, a variable is passed instructing Sonar where to find the test result data.

Fixes: gh-6092
jzheaux pushed a commit that referenced this issue Nov 26, 2018
This commit ensures that jacocoTestReport task is called when running the Sonar stage.
Additionally, a variable is passed instructing Sonar where to find the test result data.

Fixes: gh-6092
@raphaelDL
Copy link
Contributor

raphaelDL commented Nov 28, 2018

@jzheaux @rwinch

I'm posting a comment here instead of the gradle-plugins repo, 'cause I think is more related with what we have in this project.

Here's what I've found

when the Jacoco plugin is applied coverage reports should be generated when calling check and test tasks.

We are preventing the reports being generated here:

gradle.taskGraph.whenReady { graph ->

A quick read into the provided issue link suggests something about caching tests results, so in order to prevent report generation every time we call test or check it is decided to generate them only when needed, that's why we need to explicitly call the task jacocoTestReport ,

Having a look at https://docs.gradle.org/5.0/release-notes.html it seems that now is solved.

With the current gradle version 4.10.2 I removed that restriction and now I have the reports generated when I call test and check

Before the change I submitted we had in the Sonar stage ./gradlew clean sonarqube....

what was going here? coverage data generated in the previous step (with test and check) were being erased because we included clean and and they were not generated again resulting in sonarqube not having that data.

Finally.... spoiler alert -Dsonar.jacoco.reportPaths='**/build/jacoco/*.exec' is not needed after all 😅 I thought we needed cause sonar wouldn't find them, but in fact the coverage data was there all the time but was gone/erased when sonarqube was executed.

@rwinch
Copy link
Member

rwinch commented Nov 28, 2018

@raphaelDL Thanks for the updates! Would you like to submit a PR to fix this?

@raphaelDL
Copy link
Contributor

Sure,

just to be sure, in this pull request I would include:

a) the deletion of the code that force us to call jacocoTestReport explicitly in build.gradle
b) revert the command called in the Jenkinsfile sonar stage from ./gradlew clean jacocoTestReport sonarqube to
./gradlew sonarqube removing the jacocoTestReport and clean tasks

🤔

@rwinch
Copy link
Member

rwinch commented Nov 29, 2018

Looks good to me @raphaelDL! Thanks :)

@raphaelDL
Copy link
Contributor

I've submitted #6199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: build An issue in the build
Projects
None yet
Development

No branches or pull requests

3 participants