Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

How to get Gradle, Scoverage and Sonarqube to work properly? #154

Open
carlspring opened this issue Feb 24, 2019 · 6 comments
Open

How to get Gradle, Scoverage and Sonarqube to work properly? #154

carlspring opened this issue Feb 24, 2019 · 6 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@carlspring
Copy link

Hi,

I would like to get Gradle and Scoverage to produce code quality and coverage checks and feed them into Sonarqube. I've outlined what I'm doing here.

In the reports, I can see issues with the code being reported. I can also see that the aggregated Scoverage report is producing code coverage numbers in the index.html file, but I can't get Sonar to display any of this.

All the details are in the Stackoverflow question, as I thought I was perhaps misconfiguring something, as I've seen that on your public instance of Sonarqube you have a "Coverage" section, which is reporting actual coverage.

Could you please explain what I'm doing wrong? How are you producing your reports? Are you using Gradle, or SBT for them? Is it a multi-module project? Is there some configuration that I'm missing?

Please, advise!

Many thanks in advance!

Martin

@mwz
Copy link
Member

mwz commented Feb 24, 2019

Hi @carlspring, it looks to me like you have misconfigured your project.

I'd recommend you to check out our example multi-module gradle project here and here is how we execute sonar-scanner for this project, which results you can see in our public SonarQube instance.

The example project is very simple so you should be able to figure out the differences between your project, but if you still struggle with it give me a shout and I could have a look at it it more details.

@mwz mwz added the question Further information is requested label Feb 24, 2019
@carlspring
Copy link
Author

carlspring commented Feb 25, 2019

Hi @mwz ,

Thank you very much for getting back to me and for pointing me to these resources. The last time I tried this, was in mid-December and I can now see that you've added full-blown exampels for Gradle, Maven and SBT on 28/12/2018! Thanks for these working examples!

I have managed to get things working locally, but I've noticed that, if there are any Scala tests that use JUnit, it doesn't seem to be collecting code coverage for them, but it still somehow factors them in and skews the code coverage number to a lower value. Have you observed this?

Also, I think it would be useful for demos and testing, if the test modules have some dummy code issues so that you can see them in the reports in Sonar.

I hope you could advise on the JUnit code coverage issue as well!

Thanks in advance,

Martin

@mwz
Copy link
Member

mwz commented Feb 25, 2019

Thank you very much for getting back to me and for pointing me to these resources. The last time I tried this, was in mid-December and I can now see that you've added full-blown exampels for Gradle, Maven and SBT on 28/12/2018! Thanks for these working examples!

👍

I have managed to get things working locally, but I've noticed that, if there are any Scala tests that use JUnit, it doesn't seem to be collecting code coverage for them, but it still somehow factors them in and skews the code coverage number to a lower value. Have you observed this?

It's not something I've come across personally (you don't see much junit tests in scala projects these days...), however so long as scoverage supports junit tests (which I'm not sure about), I can't see any obvious reasons why those wouldn't be taken into account. We process scoverage reports directly, so if you can see junit tests in the report and the metrics for statement, branch and line coverage are not reported correctly in SonarQube, then there could be an issue somewhere. There is another aspect to coverage, which are metrics for unit test count, test duration and the numbers of skipped and failed tests (which we implemented not that long ago in 7.3), so if you're looking for those in the latest LTS release (6.7) you won't find them there as we haven't backported this feature yet.

Also, I think it would be useful for demos and testing, if the test modules have some dummy code issues so that you can see them in the reports in Sonar.

Yes, we introduced some code issues to the example projects for demonstration purposes, e.g. see here for all the issues for the multi-module sbt project.

@carlspring
Copy link
Author

Hi,

Thanks for these useful clarifications!

I'm afraid we're actually using 5.6.7 and we're getting an upgrade to 6.7.6, or closest 6.x LTS in the (hopefully) near future. Due to circumstances beyond our control (that I don't want to get into, but picture a large corporation moving slowly), it's unlikely that we will be upgrading to Sonarqube 7.x soon. Is there a likelihood of getting those metrics backported to Sonarqube 6.7.x, or will that not be worth the effort, (or even possible)?

In regards to the JUnit issue -- would it be possible for you to give it a go? Just a simple "Hello, World!" with a test in Scala using JUnit and code coverage reports with Scoverage in Sonarqube? I'm curious to see, if the issue is on my side, or if it is indeed a problem with Sonar Scala.

Also, we have a massive code base in Scala, but we're using Gradle to build the code. Very few of our teams are using SBT, since our way of working (which is a heavily customized non-industry-standard approach) fits better with what Gradle can provide us. This is why the SBT examples will probably not be of as much interest, as the ones for Gradle. Nevertheless, I will have a look at them to see what extra value we could get out of them. Thanks! :)

@mwz
Copy link
Member

mwz commented Feb 28, 2019

Is there a likelihood of getting those metrics backported to Sonarqube 6.7.x, or will that not be worth the effort, (or even possible)?

Yes, I think that I will get those backported quite soon - stay tuned for the updates.

In regards to the JUnit issue -- would it be possible for you to give it a go?

Junit tests with Gradle is quite an unusual setup for me, but I'd be happy to investigate and fix the issue (if possible) if you can provide an example project for me to look at.

@mwz
Copy link
Member

mwz commented Mar 2, 2019

FYI, here are the extra unit test metrics backported to the LTS series #164. I should be able to release it soon.

@mwz mwz added the help wanted Extra attention is needed label Dec 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants