Skip to content
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

Add support for the new Sonar Gradle runner plugin #100

Open
PabloThiele opened this issue Sep 15, 2017 · 6 comments
Open

Add support for the new Sonar Gradle runner plugin #100

PabloThiele opened this issue Sep 15, 2017 · 6 comments

Comments

@PabloThiele
Copy link

Hi, since the actual valid plugin to send configuration to SonarQube is this one : https://plugins.gradle.org/plugin/org.sonarqube

The actual documentation is outdated.

I tried to follow the instructions and some workarounds and no one had success.

I'm using the:
classpath 'com.bmuschko:gradle-clover-plugin:2.1.2'
id "org.sonarqube" version "2.5"
SonarQube 5.6 LTS

@Alex-Vol
Copy link
Collaborator

I will attempt to see if this can still be integrated. I did not have luck when I read the new plugin information. But I did not spend too much time. If I can perform the setup I will write a new page for the settings necessary.

@Alex-Vol Alex-Vol added this to the 2.1.4 milestone Sep 17, 2017
@Alex-Vol-SV Alex-Vol-SV modified the milestones: 2.1.4, 3.0.0 Dec 24, 2017
@Alex-Vol Alex-Vol removed this from the 2.2.0 milestone Dec 28, 2017
@Alex-Vol
Copy link
Collaborator

Alex-Vol commented Jan 5, 2018

I spent some time researching what this issue is all about. Here is what I have found so far.

The clover plugin for SonarQube is not up-to-date for the latest API. Using this plugin in SonarQube enables pushing Clover reports and parsing the information so SonarQube can display and use it. The new SonarQube Gradle plugin probably supports the same property configuration that is needed to produce results but without the clover plugin for SonarQube this goes nowhere.

I am tempted to fix the issues that prevent that stale clover plugin for SonarQube and make a pull request but that is more that I have time for. If I get around to it then I will prove this still works and make some instructions available here.

Sonar-Clover

@mmindenhall
Copy link

I'm using the sonar clover plugin successfully with SonarQube 7. After enabling the plugin on the server, I did the following.

In gradle.properties:

systemProp.sonar.host.url=http://my-sonar.com
systemProp.sonar.host.login=<key created by sonar>
systemProp.sonar.clover.reportPath=build/reports/clover/clover.xml

In build.gradle:

apply plugin: 'com.bmuschko.clover'
apply plugin: 'org.sonarqube'

clover {
    targetPercentage = '90%'

    excludes = [
            '**/ExcludedClass.java',
            '**/excludedpackage/*.*',
    ]
    // set property that will be read by sonar plugin to match coverage exclusions
    project.ext.'sonar.coverage.exclusions' = excludes.join(',')

    report {
        html = true
        xml = true
    }
}

sonarqube {
    properties {
        // read coverage exclusions set by clover
        property "sonar.coverage.exclusions", project.ext.'sonar.coverage.exclusions'
    }
}

build.finalizedBy cloverGenerateReport

A few notes on the above:

  1. The sonarqube block is only needed if you are excluding files or packages within the clover block.
  2. If files/packages are excluded, a property is being set (at the gradle project level) by the clover block, which is then being read by the sonarqube block. Without this, the code coverage you see on the sonar server will not match what you see in the clover report.
  3. The build.finalizedBy cloverGenerateReport generates the report at the end of the gradle build stage.

With this configuration, when I run my build with ./gradlew clean build sonarqube, I see the correct code coverage for the project on the sonar server.

So without any integration, these two plugins are working together. However, it would be awesome to have this plugin set the sonar.coverage.exclusions property (and any other relevant properties) within the org.sonarqube plugin if it is detected within the project.

@Alex-Vol
Copy link
Collaborator

Alex-Vol commented Apr 6, 2018

Thank you @mmindenhall for this information. I can see about having something akin to what you specified added to this plugin. It would be relatively easy for the plugin to react to the presence of the "org.sonarqube" plugin and add the extra properties.

At a minimum I may add a paragraph in the README.md file documenting your experience with this integration.

@mmindenhall
Copy link

I looked into ways to integrate the two plugins, and concluded that either the sonar-scanner-gradle plugin would need to expose a way to set a property from within another plugin's code (doesn't seem possible the way the plugin is implemented), or this plugin would need to add a way to retrieve properties from other plugins. I then posted in the SonarQube Google group, and received this response:

Hi,

You can also think the other way around: the SonarQube plugin can detect the presence of the clover plugin, and extract configuration from it. This is something we already do for JaCoCo and Android. The only question is to know if the Clover plugin expose a stable API to get the data you need, because having to deal with breaking API changes depending on the plugin version is a nightmare.

++

Julien

For consistency, it sounds like the best approach would be to expose the relevant properties within this plugin, and read them from the sonar-scanner-gradle plugin.

@Alex-Vol
Copy link
Collaborator

Alex-Vol commented Apr 10, 2018

You can read the clover Closure parameters just as much as set them. You already do that.

The same could be done in the Sonar plugin. The join() code you added could be part of the Sonar plugin operation.

Illustration using your example.

apply plugin: 'com.bmuschko.clover'
apply plugin: 'org.sonarqube'

clover {
    targetPercentage = '90%'

    excludes = [
            '**/ExcludedClass.java',
            '**/excludedpackage/*.*',
    ]
    report {
        html = true
        xml = true
    }
}

sonarqube {
    properties {
        // read coverage exclusions set by clover
        property "sonar.coverage.exclusions", project.clover.excludes.join(',')
    }
}

build.finalizedBy cloverGenerateReport

FYI, the clover extension has been part of this plugin since the beginning and the excludes part has not changed much at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants