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

Configurations for effort and reportLevel are broken. #972

Open
victorwss opened this issue Sep 30, 2023 · 17 comments
Open

Configurations for effort and reportLevel are broken. #972

victorwss opened this issue Sep 30, 2023 · 17 comments

Comments

@victorwss
Copy link

I am using spotbugs gradle plugin version 6.0.0-beta.3 with Spotbugs 4.7.3, Gradle 8.4-rc-2 and Java 21.

Trying to recompile an old project give some problems. It seems that the effort and reportLevel are broken.

My gradle file used to contain that:

spotbugs {
    toolVersion = versionSpotBugs
    effort = "max"
    reportLevel = "low"
    omitVisitors = ["WeakExceptionMessaging", "OverlyPermissiveMethod"]
    ignoreFailures = true
}

It gives the following error:

Cannot set the value of extension 'spotbugs' property 'effort' of type com.github.spotbugs.snom.Effort using an instance of type java.lang.String.

After fixing it, it also complains about reportLevel not being an instance of Confidence. For fixing it, I needed to change it to that:

spotbugs {
    toolVersion = versionSpotBugs
    effort = com.github.spotbugs.snom.Effort.MAX
    reportLevel = com.github.spotbugs.snom.Confidence.values()[0]
    omitVisitors = ["WeakExceptionMessaging", "OverlyPermissiveMethod"]
    ignoreFailures = true
}

Using com.github.spotbugs.snom.Confidence.LOW doesn't works for some reason that I couldn't understand, it seems that it somehow wrongly thinks that LOW is a class.

Anyway, I doubt that this change was intended, at least not in the way it is.

I can provide a minimal project reproducing it, if you really need to.

@hazendaz
Copy link
Member

hazendaz commented Oct 1, 2023

Hi @victorwss, try taking a look over at spotbugs main project https://github.com/spotbugs/spotbugs/blob/master/gradle/java.gradle. I just got that updated to 6.0.0-beta.3 and like you likely ran into it did not work per release notes options to try. Not sure if it will help you or not but worth taking a look.

@KengoTODA
Copy link
Member

Could you check "Changes for Kotlin buildscripts" in the changelog for beta.1 release? Hope that it helps you.

@Vest
Copy link

Vest commented Oct 3, 2023

I confirm, my Gradle project doesn't like "low" as a string too. I had to use Confidence.valueOf('low') to overcome the error. But unfortunately, the import of the package doesn't work either. It seems that the classpath doesn't have required jars, or so.

@victorwss
Copy link
Author

So, if I'm understanding correctly, this was somewhat intended?

Anyway, it would be really appreciated if you could somehow either completely forgive the user for that or perhaps give a warning and continue business as usual in order to avoid breaking existing buildscripts without an outstanding reason for that when people are just bumping up dependencies.

Or, at least fail with a very clear and direct error message telling what should be done to fix other than just "Dude, it is not a string anymore, it is now an enum. Good luck figuring out in Google how to fill in this correctly."

Or minimally, make reportLevel = com.github.spotbugs.snom.Confidence.LOW work.

Anyway, the change is not a big deal. For now, I will stick to effort = com.github.spotbugs.snom.Effort.MAX and reportLevel = com.github.spotbugs.snom.Confidence.valueOf("LOW") (as suggested by @Vest). No need to import stuff because that don't really make the situation any better.

Keep up with the good job!

@Vest
Copy link

Vest commented Oct 18, 2023

try taking a look over at spotbugs main project

I have stolen your code from the java.build file:

def classLoader = plugins['com.github.spotbugs'].class.classLoader
def SpotBugsTask = classLoader.findLoadedClass( 'com.github.spotbugs.snom.SpotBugsTask' )
def SpotBugsEffort = classLoader.findLoadedClass( 'com.github.spotbugs.snom.Effort' )
def SpotBugsConfidence = classLoader.findLoadedClass( 'com.github.spotbugs.snom.Confidence' )
...
reportLevel = SpotBugsConfidence.LOW

Seems it does the job. Can you please tell me, why is this working? Why have you decided to write it like that?
When I was trying to write import com.github.spotbugs.snom.Confidence, I was always getting an error Could not get unknown property 'com' for extension 'spotbugs' of type java.lang.Object.

@hazendaz
Copy link
Member

Hi @Vest I'm still too new to gradle to understand the why. I had issues to until I did that. It didn't quite make sense to me either. If I recall, I saw another part of the script that did something similar so I gave that a shot.

@sebastian-peter
Copy link

Same problem here, using a separate gradle file to configure spotbugs. Using the classloader works, but seems a bit hacky to me - there has to be a better way?

@javintx
Copy link

javintx commented Dec 13, 2023

Same problem here, using a separate gradle file to configure spotbugs. Using the classloader works, but seems a bit hacky to me - there has to be a better way?

I'm using the gradle plugin 6.0.2 with gradle 8.5 and I have the same problem. I'm using a separate gradle file to configure spotbugs. The classloader solution works fine, but it's too tricky and a bit ugly.

When I was trying to write import com.github.spotbugs.snom.Confidence, I was always getting an error Could not get unknown property 'com' for extension 'spotbugs' of type java.lang.Object. And the same for the effort value.

Is there a better way to configure spotbugs in a different gradle file?

@pbilstein
Copy link

Same problem here as @javintx and @sebastian-peter

Using a separate groovy gradle file to configure spotbugs and using ugly classloader workaround works. Would like to get rid of it.

BenSartor added a commit to simlar/simlar-server that referenced this issue Dec 29, 2023
  * In case you wonder, the following does not work:
```
reportLevel = com.github.spotbugs.snom.Confidence.LOW
```
  * see: spotbugs/spotbugs-gradle-plugin#972
BenSartor added a commit to simlar/simlar-server that referenced this issue Dec 29, 2023
  * In case you wonder, the following does not work:
```
reportLevel = com.github.spotbugs.snom.Confidence.LOW
```
  * see: spotbugs/spotbugs-gradle-plugin#972
@ArtemioRamirez
Copy link

Having the same issue the example shown on https://github.com/spotbugs/spotbugs-gradle-plugin using

// require Gradle 8.2+
import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort
spotbugs {
    ignoreFailures = false
    showStackTraces = true
    showProgress = true
    effort = Effort.DEFAULT
    reportLevel = Confidence.DEFAULT
    visitors = listOf("FindSqlInjection", "SwitchFallthrough")
    omitVisitors = listOf("FindNonShortCircuit")
    reportsDir = file("$buildDir/spotbugs")
    includeFilter = file("include.xml")
    excludeFilter = file("exclude.xml")
    baselineFile = file("baseline.xml")
    onlyAnalyze = listOf("com.foobar.MyClass", "com.foobar.mypkg.*")
    maxHeapSize = "1g"
    extraArgs = listOf("-nested:false")
    jvmArgs = listOf("-Duser.language=ja")
}

Literally doesn't work and will fail with message:

Cannot set the value of extension 'spotbugs' property 'reportLevel' of type com.github.spotbugs.snom.Confidence using an instance of type java.lang.Class.

@KaurKadakWise
Copy link

Same error for me, could not add import com.github.spotbugs.snom.Effort into gradle file using Groovy DSL. Encountered exception

@ASullivan219
Copy link

Same problem here for me as well cannot import the Confidence object. The only thing that works is the class loader option referenced above from the user Vest.

@Azhrei
Copy link

Azhrei commented Apr 5, 2024

Another bump.

This is fairly important — the documentation describes how to do something and it CLEARLY doesn't work. This is going to trip up a lot of developers until either the documentation is corrected or the bug is fixed!

@ben-wharton
Copy link

Unfortunately spent a lot of time trying to fix this issue, didn't find a better solution than the classloader solution above.

@NaradaBW
Copy link

NaradaBW commented Aug 6, 2024

same

@david-vasconcelos-tw
Copy link

same here

@kybercryst4l
Copy link

kybercryst4l commented Aug 27, 2024

Until it's fixed i'm using:

import com.github.spotbugs.snom.Confidence
import com.github.spotbugs.snom.Effort
spotbugs {
   effort = Effort.MAX
   // 0: LOW, 1: MEDIUM, 2: DEFAULT, 3: HIGH
   reportLevel = Confidence.values()[2]
   [...]
}

Using Effort.MAX is woking, if not, Effort.values()[2] should also work.

karianna added a commit to PCGen/pcgen that referenced this issue Sep 30, 2024
* Initial cut for Java 21 support + lots of debug

* Update PMD to 7.0.0-rc4

* PMD now passes

* Checkstyle now passes

* grdle 8.5 for full Java 21 support

* Use official monocole

* Initial cut for Java 21 support + lots of debug

* Update PMD to 7.0.0-rc4

* PMD now passes

* Checkstyle now passes

* grdle 8.5 for full Java 21 support

* Updates to reflect latest 17 and 21 releases

* Tidy-up after 1st successful build

* Tidy-up after 1st successful build

* Tidy-up after 1st successful build

* Updated:
pmd to 7.0.0
gradle to 8.7
checkstyle to 10.15.0
spotbugs to 4.8.3

* PMD updates

* Formatted output for downloadJRE and downloadJavaFXModules a little.
Refactored code a little
Removed few warnings detected by IDEA.

* Removed an unnecessary empty line.

* Use Linux 21.0.1 for aarch64 JavaFX
Removed trailing spaces (IDEA)
Applied few recommendations from Spotbugs (just to test it)

* Updated Spotbugs Plugin to 6.0.9 (the solution was taken from spotbugs/spotbugs-gradle-plugin#972 (comment))

* Update deps

* Initial cut for Java 21 support + lots of debug

* Update PMD to 7.0.0-rc4

* PMD now passes

* Checkstyle now passes

* grdle 8.5 for full Java 21 support

* Initial cut for Java 21 support + lots of debug

* Update PMD to 7.0.0-rc4

* PMD now passes

* Updates to reflect latest 17 and 21 releases

* Tidy-up after 1st successful build

* Tidy-up after 1st successful build

* Tidy-up after 1st successful build

* Updated:
pmd to 7.0.0
gradle to 8.7
checkstyle to 10.15.0
spotbugs to 4.8.3

* PMD updates

* Formatted output for downloadJRE and downloadJavaFXModules a little.
Refactored code a little
Removed few warnings detected by IDEA.

* Removed an unnecessary empty line.

* Use Linux 21.0.1 for aarch64 JavaFX
Removed trailing spaces (IDEA)
Applied few recommendations from Spotbugs (just to test it)

* Updated Spotbugs Plugin to 6.0.9 (the solution was taken from spotbugs/spotbugs-gradle-plugin#972 (comment))

* Update deps

* Last fixes for full pre release build to work

* Add comments for removal of SecurityManager

* * updated com.github.spotbugs to 6.0.15
* updated checkstyle to 10.17.0
* updated pmd to 7.1.0
* updated spotbugs to 4.8.5

* Corrected the distTar failure on Windows (#152)

* Corrected the error UncheckedIOException related to the buildDirectory. It was resolved by Gradle to `C:...\pcgen\property(org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactorySFixedDirectory, C:...\pcgen\build))\launch4j`
Updated few dependencies as well.

Signed-off-by: Vest <[email protected]>

* Formatted build.gradle, by putting a space character after "version:"

Signed-off-by: Vest <[email protected]>

---------

Signed-off-by: Vest <[email protected]>

* Removed explicit "buildDirectory" variable. Replaced it with the lazy layout.buildDirectory
Replaces projectDir with layout.projectDirectory, because the variable projectDir hides the property Project.projectDir
Replaced "new File" with "file"
Replaced many "eager" tasks with lazy tasks.register.
Reconfigured many tasks in a lazy way
Updated task-tree to v4.0.0
Renamed task all to allTasks, because it was confusing what it does.
Formatted few lines in build scripts.

Signed-off-by: Vest <[email protected]>

* Added an explicit dependency between tasks -> this should be changed to input/output files instead (because the Jar task creates an *output* file, that will be an *input* file for the copyToOutput task).
Corrected a wrong code of genProjectNsis

Signed-off-by: Vest <[email protected]>

* converted genProjectNsis to the "lazy" API. Removed buildDirectory as a variable, replaced it with layout.buildDirectory

Signed-off-by: Vest <[email protected]>

* converted buildNsis to the "lazy" API.

Signed-off-by: Vest <[email protected]>

* Removed 32-bit version from pcgen.nsi (NSIS installer)
Replaced few tasks creation calls with the "register".
Added /WX key (fail with warnings) for NSIS
Corrected few "delete" calls

Signed-off-by: Vest <[email protected]>

* Upgrade Grade wrapper from 8.7 to 8.8

Signed-off-by: Vest <[email protected]>

* Formatted code a little, replaced $projectDir with layout.projectDirectory
Fixed failed :prepareRelease task. Formatted the description, so it will not have a long line in source code.

Signed-off-by: Vest <[email protected]>

* Fixed a typo in the property name (build.gradle)

* Corrected an issue with JavaFX modules (a wrong relative folder was used).
Simplified the :idea task using "fileTree"

* Corrected the :genDataList task

* Refactored release.gradle, this reduced the number of lines.

* Refactored release.gradle, this reduced the number of lines.

* Replaced eager tasks with lazy
Replaced projectDir with layout.projectDirectory
Moved :downloadJRE and :downloadJavaFXModules to the "lazy" (doLast) section. Now, JRE and JavaFX modules are downloaded only, when the task is required/called.
Slightly improved the logging for :downloadJRE
Detached :downloadJRE from :downloadJavaFXModules (they are independent). Removed codes, where the modules and JDK were extracted. It seems that the new JDK doesn't have files that we omitted in the past.
Adjusted dependencies, because :downloadJRE is an independent task now.
Formatted pcgen.nsi

* Corrected the broken tasks: :jpackageImage, :buildNsis
Removed :clean from :prepareRelease.

* Corrected types of Files in :checksum

Signed-off-by: Vest <[email protected]>

* Refactored build.gradle:
* renamed :all to :allTasks in comments
* :downloadJavaFXModules is lazy, tries to reuse the downloaded files, removes empty folders (Window JRE still contains empty folders - this is TODO)
* :downloadJavaFXModules remove local "mods/" from the task. This task is used to download modules for all supported platforms only
* :downloadJavaFXLocal added for local builds only (used for different tests, for :run). It isn't used for packaging, but for compilation only
* :extractJavaFXLocal extracts downloaded JavaFX binaries into mods/.
* :compileJava - we don't download all JREs and JavaFX artifacts anymore. Added a dependency to :extractJavaFXLocal
* :test - removes dependencies to :downloadJRE, :downloadJavaFXModules

Corrected a typo in build-gradle.xml Ant
Now we add :compileJava as a direct dependency to all ant tasks, where plugins are built.

* Removed unhelpful println calls from some tasks such as :copyToLibs or :downloadJRE
Corrected a bug in :downloadJRE, now we delete the JDK folder, if it contains an old JDK. Previously, we couldn't extract JDK into it (unfortunately, the deletion removes JavaFX, if it has been downloaded previously).
:downloadJavaFXLocal - OS_NAME isn't used, because it is "private"
:clean moved to the bottom, and it deletes probably everything.
:run doesn't require all JDKs and all JavaFX modules. It simply depends on :extractJavaFXLocal now. Two dependencies were removed.
Slightly improved the logging of :buildNsis, but this steps requires more testing.

* Fixed a broken plugin, caused by 187f6c2

* Removed println in PlayerCharacter.java, that was added in #7056

* Updated dependencies in build.gradle and reporting.gradle

* Upgraded pmd found several issues in source code that were corrected:
* This collection could be an EnumMap
* Unnecessary explicit array creation for varargs method call
* Lambda expression could be written as a method reference: xxxxxx::yyyyyyy

* Mistakenly collapsed imports in a previous commit, and violated :checkstyleMain

* Upgraded gradlew to 8.9
Refactored :downloadJavaFXModules, :downloadJRE, :genDataList, :genProjectNsis to support "up-to-date" (kind of a caching) feature from gradle
Added more logging to :buildNsis

* Moved the creation of the nsisRelease folder from :genProjectNsis to :buildNsis

* Fixed *.xsl templates: they were using a function str:substring-after-last from xsltsl (https://www.w3.org/TR/xslt11/). The second parameter has the name "chars", but the code was using "char".

* Refactored :jpackage, and made is shorter.

* :clean - delete files/folders that are generated during the build.

* :clean - delete files/folders that are generated during the build: outputsheets/d20/western/htmlxml/psheet_fantasy_std.htm

* Refactored :copyMasterSheets

* Attempt to resolve the bug, when the JRE is packaged before JavaFX modules are downloaded.

* Upgraded JDK and JavaFX to 21.0.4

* Language bundle date updates

* Refactored Gradle scripts to support Mac builds (#175)

* Upgraded Gradle wrapper to 8.10.2

* Updated com.github.spotbugs to 6.0.23
Updated checkstyle to 10.18.1
Updated pmd to 7.6.0
Reffactored Main.java -> use streams, now it has a "draft" branch that is executed, when the application is launched from Mac's bundle

* Fixed an error in ConfigurationSettings.java detected by Checkstyle.

* Corrected a logical error in ConfigurationSettings.java

---------

Signed-off-by: Vest <[email protected]>
Co-authored-by: Vest <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests