kelloggm / checkerframework-gradle-plugin

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

Support Gradle version catalog #278

Closed alexvas closed 5 months ago

alexvas commented 5 months ago

Please support gradle version catalog to specify a Checker Framework version.

Actual behavior:

Given in gradle/libs.versions.toml:

checker-qual = { group =  "org.checkerframework", name =  "checker-qual", version =  "3.44.0" }

and also in build.gradle:

dependencies {
    compileOnly libs.checker.qual
    testCompileOnly libs.checker.qual
    checkerFramework libs.checker.qual
}

Then there is a warning when gradle configuring a project:

No explicit dependency on the Checker Framework found, using default version 3.44.0

Given plain string in build.gradle:

dependencies {
  compileOnly 'org.checkerframework:checker-qual:3.44.0'
  testCompileOnly 'org.checkerframework:checker-qual:3.44.0'
  checkerFramework 'org.checkerframework:checker:3.44.0'
}

Then no warning issued.

Expected behavior:

There should be no difference specifying Checker framework version either as a plain string or via Gradle version catalog.

kelloggm commented 5 months ago

There are two parts of the Checker Framework that need to be specified:

In your first example, the gradle/libs.versions.toml file only defines a dependency on the first of these (checker-qual), and the warning that you're seeing is about the second. In other words, that version catalog only specifies an annotation version but not a checker version, so the plugin uses the default (and so you see the message about No explicit dependency...).

In your plain build.gradle example, note that the checkerFramework dependency's artifact id is checker and not checker-qual.

alexvas commented 5 months ago

My bad. Thank you. Just for the reference, working example using Gradle version catalog would be:

gradle/libs.versions.toml:

[versions]
checker-plugin-version = "0.6.40"
checker-framework-version = "3.44.0"

[libraries]
checker-qual = { group =  "org.checkerframework", name =  "checker-qual", version.ref =  "checker-framework-version" }
checker-framework = { group =  "org.checkerframework", name =  "checker", version.ref =  "checker-framework-version" }

[plugins]
checker-plugin = { id = "org.checkerframework", version.ref = "checker-plugin-version" }

and in build.gradle:

plugins {
    id 'java'
    alias(libs.plugins.checker.plugin)
}

dependencies {
    compileOnly(libs.checker.qual)
    testCompileOnly(libs.checker.qual)
    checkerFramework(libs.checker.framework)
}

checkerFramework {
    checkers = [
            'org.checkerframework.checker.nullness.NullnessChecker'
    ]
}