kelloggm / checkerframework-gradle-plugin

Gradle plugin to use the Checker Framework for Java
Apache License 2.0
66 stars 15 forks source link

Add depencency automatically #274

Open koppor opened 3 months ago

koppor commented 3 months ago

I applied the plugin using the default configuration (as outlined in the README.md)

diff --git a/build.gradle b/build.gradle
index 41dd4e548d..3d49dba9df 100644
--- a/build.gradle
+++ b/build.gradle
@@ -24,6 +24,9 @@ plugins {

     id 'checkstyle'

+    // Homepage: https://github.com/kelloggm/checkerframework-gradle-plugin
+    id 'org.checkerframework' version '0.6.40'
+
     id 'project-report'

     id 'idea'
@@ -38,6 +41,8 @@ apply plugin: XjcPlugin

 apply from: 'eclipse.gradle'

+apply plugin: 'org.checkerframework'
+
 group = "org.jabref"
 version = project.findProperty('projVersion') ?: '100.0.0'

@@ -616,6 +621,13 @@ checkstyle {
     sourceSets = []
 }

+checkerFramework {
+    checkers = [
+            'org.checkerframework.checker.nullness.NullnessChecker',
+            'org.checkerframework.checker.units.UnitsChecker'
+    ]
+}
+
 rewrite {
     activeRecipe(
         'org.jabref.config.rewrite.cleanup'

I get an error

error: AnnotationBuilder: fromClass can't load class org.checkerframework.dataflow.qual.Deterministic
  Is the class in checker-qual.jar?

I saw at https://github.com/kelloggm/checkerframework-gradle-plugin/issues/263 and https://github.com/kelloggm/checkerframework-gradle-plugin?tab=readme-ov-file#specifying-a-checker-framework-version that one can specify some dependencies manually.

I would expect that the MWE shown in the README.md works. Maybe, its just a simple thing, but still causes trouble also by others https://stackoverflow.com/q/75648606/873282.

koppor commented 3 months ago

Related: The dependency report shows following issue:

checkerFrameworkAnnotatedJDK - A copy of JDK classes with Checker Framework type qualifiers inserted.
\--- org.checkerframework:jdk8:3.44.0 FAILED
kelloggm commented 3 months ago

I would expect that the MWE shown in the README.md works

Fair enough - it should! I'm not sure what's causing the problem that you're encountering, but almost certainly there is some kind of interference between the Checker Framework and one of your project's other dependencies.

I saw at https://github.com/kelloggm/checkerframework-gradle-plugin/issues/263 and https://github.com/kelloggm/checkerframework-gradle-plugin?tab=readme-ov-file#specifying-a-checker-framework-version that one can specify some dependencies manually.

Do you see the same problem if you explicitly request a version of checker-qual as a compileOnly (or compileOnlyApi or api) dependency?

Maybe, its just a simple thing, but still causes trouble also by others https://stackoverflow.com/q/75648606/873282.

The problem in that issue is only tangentially related to the problem that you've encountered: that person is using Maven (which doesn't have a plugin that automatically adds the necessary dependencies), and forgot the checker-qual dependency when specifying the dependencies manually. That's exactly the sort of problem that this plugin exists to avoid (though in your case ).

Related: The dependency report shows following issue:

This issue is unlikely to be related, since unless you're on Java 8 that dependency isn't used, and even then it's optional - it contains the default set of annotations for Java 8 JDKs.