spotbugs / spotbugs-gradle-plugin

https://plugins.gradle.org/plugin/com.github.spotbugs
Apache License 2.0
180 stars 68 forks source link

Cannot configure reports via property access anymore #235

Open jochenberger opened 4 years ago

jochenberger commented 4 years ago

In 3.x, you could write

    spotbugsMain.reports.xml.enabled = false

If you try that with 4.0(.5), you get

 > Could not get unknown property 'xml' for SpotBugsReport container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer.

You have to use

    spotbugsMain.reports {
        xml.enabled = false
    }
KengoTODA commented 4 years ago

I guess you upgraded not only spotbugs-gradle-plugin but also Gradle.
It could be problem of Gradle side. Make sure you can reproduce this problem with spotbugs-gradle-plugin v3 and the latest Gradle version. If you can reproduce, we're sure that it's not our problem, so we can close this issue safely.

refs #95

jochenberger commented 4 years ago

I can't.

KengoTODA commented 4 years ago

Then please share the mcve project to reproduce. Thanks! But actually what this plugin uses is a Gradle official plugin, so I'm not sure we can provide a fix or not.

jochenberger commented 4 years ago

Just add this build file in an empty directory and run gradle spotbugsMain.

groovy
plugins {
  id "com.github.spotbugs" version '4.0.7'
}

repositories {
    jcenter()
}

apply plugin: 'java'
spotbugsMain.reports.xml.enabled = false
jochenberger commented 4 years ago

Could it be that the time that the reports objects are created changed from the 3.x releases? It looks as if the xml entry is not yet created at the time that I try to disable it.

KengoTODA commented 4 years ago

Yes it's recreated, to eliminate the dependency on Gradle's internal API.

In v3.0.0 we have the SpotBugsReport interface which extends a Gradle internal API. So in v4.0.0 we changed it to a plain NamedDomainObjectContainer<SpotBugsReport>.

I'll try to solve this issue, by making a SpotBugsReport interface which extends NamedDomainObjectContainer, and delegate to getByName(String) like v3.0.0.

KengoTODA commented 4 years ago

I'll try to solve this issue, by making a SpotBugsReport interface which extends NamedDomainObjectContainer, and delegate to getByName(String) like v3.0.0.

This way doesn't work, because

A workaround is that, configure the reports property of SpotBugsTask like below, but it breaks another backward compatibility: 'can generate a report in specified reportsDir' test in ReportFunctionalTest.

.configure {
    it.create("xml").setEnabled(false);
    it.create("html").setEnabled(false);
    it.create("text").setEnabled(false);
}

So for now, we have no solution on this issue. We may handle this as an intentional breaking change. :sob:

vorburger commented 4 years ago

FYI: I've run into this issue during https://issues.apache.org/jira/browse/FINERACT-947, and inspired by https://github.com/spotbugs/spotbugs-gradle-plugin#configure-the-spotbugstask, have replaced our:

// To generate an HTML report instead of XML
tasks.withType(SpotBugsTask) {
    reports.xml.enabled = false
    reports.html.enabled = true
    reportLevel = "high"
}

with:

// To generate an HTML report instead of XML
spotbugs {
    reportLevel = 'high'
}
spotbugsMain {
    reports {
        html {
            enabled = true
            stylesheet = 'fancy-hist.xsl'
        }
    }
}
spotbugsTest {
    reports {
        html {
            enabled = true
            stylesheet = 'fancy-hist.xsl'
        }
    }
}
spotbugsIntegrationTest {
    reports {
        html {
            enabled = true
            stylesheet = 'fancy-hist.xsl'
        }
    }
}

Note also new issue #242.

SimoneCusimano commented 4 years ago

+1. Same issue with Spotbugs v4.0.3 and spotbugs-gradle-plugin v4.2.1.

It publishes the reports in mail.xml regardless the path defined with xml.destination or html.destination

maoai-xianyu commented 2 years ago

spotbugs classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.10" spotbugs 'com.github.spotbugs:spotbugs:4.5.0'

when i use report. but it just create one report. html or xml . now i want to create both reports.
Generate HTML and XML reports at the same time,how can i do


 reports {
       xml.configure {
            required = true
            outputLocation = file("$reportsConfigDir/spotbugs/spotbugs.xml")

        }

        html.configure {
            required = true
            outputLocation = file("$reportsConfigDir/spotbugs/spotbugs.html")
            stylesheet = 'fancy-hist.xsl'
        }
    }

how can i do ?