nebula-plugins / gradle-lint-plugin

A pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts.
Apache License 2.0
761 stars 88 forks source link

Unused-dependency rule falsely reports on lombok not being used at compile time. #376

Open Grimoren opened 2 years ago

Grimoren commented 2 years ago

needs fixing unused-dependency this dependency is a service provider unused at compileClasspath time and can be moved to the runtimeOnly configuration build.gradle:19 compileOnly(group: "org.projectlombok", name: "lombok", version: projectlombokLombokVersion)

fixed unused-dependency this dependency is unused and can be removed build.gradle:19 compileOnly(group: "org.projectlombok", name: "lombok", version: projectlombokLombokVersion)

error: package lombok does not exist import lombok.Getter; ^

jbennett2091 commented 1 year ago

The easy work-around is to make it an implementation dependency, instead of a compileOnly. Has implications, and compileOnly would be preferred, but gets you running

Grimoren commented 1 year ago

Actually it still identifies it as not used in implementation, as well.

mikesmithson commented 1 year ago

You might want to just use the gradle-lombok plugin instead and not have to deal dependency scopes for lombok anymore: https://plugins.gradle.org/plugin/io.freefair.lombok

dbolger commented 2 months ago

The Getter annotation and any other annotation that has a RetentionPolicy @Retention(RetentionPolicy.SOURCE) will always fail. The Gradle Lint plugin uses ASM to visit compiled class files and review if dependencies declared are in use in said compiled classes. JLS 9.6.4.2 states that the information about this annotation will not be present in the compiled class file:

Annotations may be present only in source code, or they may be present in the binary form of a class or interface. An annotation that is present in the binary form may or may not be available at run time via the reflection libraries of the Java SE Platform. The annotation type java.lang.annotation.Retention is used to choose among these possibilities.

If an annotation a corresponds to a type T, and T has a (meta-)annotation m that corresponds to java.lang.annotation.Retention, then: ... If m has an element whose value is java.lang.annotation.RetentionPolicy.SOURCE, then a Java compiler must ensure that a is not present in the binary representation of the class or interface in which a appears.

https://docs.oracle.com/javase/specs/jls/se14/html/jls-9.html#jls-9.6.4.2

The only way I can imagine one would be able to determine if these annotations were being used would be to investigate the source file itself.