gradle-dependency-analyze: False Positive on Unused Dependency Analysis
Description:
I am encountering an issue while using the dependency-analysis Gradle plugin in our project.
We are working on switching to jakarta compatible Nonnull and Nullable annotations. We were using com.google.code.findbugs:jsr305 and now we want to switch to jakarta.annotation:jakarta.annotation-api .
We just updated dependency from com.google.code.findbugs:jsr305 to jakarta.annotation:jakarta.annotation-api in our project dependencies and renamed from jakarta.annotation.Nonnull , jakarta.annotation.Nullable to jakarta.annotation.Nonnull, jakarta.annotation.Nullable usage in the classes.
After the update, analyzeClassesDependencies task is reporting that the jakarta.annotation:jakarta.annotation-api dependency is unused in the project.
However, this dependency is indeed being used in multiple places within the codebase, in the multiple classes.
Cleaning the gradle cache didn’t help as well.
To Reproduce I tried to reproduce the issue with simple project but i couldn’t. I suspect that it is something could be related to our usage or project structure.
Tried to have some debug / trace logs from the plugin as described in https://github.com/gradle-dependency-analyze/gradle-dependency-analyze/issues/306 and https://github.com/gradle-dependency-analyze/gradle-dependency-analyze?tab=readme-ov-file#task-configuration but output log file doesn’t contain any details. log content was:
unusedDeclaredArtifacts
- jakarta.annotation:jakarta.annotation-api:2.1.1@jar
Versions
gradle-dependency-analyzer : 1.9.1 and ‘1.9.2’
Expected behaviour The analyzeClassesDependencies task should recognize the usage of jakarta.annotation:jakarta.annotation-api in my code and not report it as an unused declared artifact.
Note: We are currently using gradle-dependency-analyzer - 1.9.1 and even we upgrade to gradle-dependency-analyzer - 1.9.2 without any change in our code or dependencies , we are getting some of the used dependencies reported as unused. Not sure if this is related but i will create an another ticket for it after investigating the current issue.
I would appreciate any guidance or assistance you can provide to resolve this issue. Please let me know if you need any additional information.
Thank you for your time and support.
Best regards,
Ramazan
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (6 by maintainers)
Commits related to this issue
- add superfluous to output in when using aggregators Closes #528 — committed to gradle-dependency-analyze/gradle-dependency-analyze by BigMichi1 2 years ago
- add superfluous to output in when using aggregators Closes #528 — committed to gradle-dependency-analyze/gradle-dependency-analyze by BigMichi1 2 years ago
- add superfluous to output in when using aggregators Closes #528 — committed to gradle-dependency-analyze/gradle-dependency-analyze by BigMichi1 2 years ago
- add superfluous to output in when using aggregators Closes #528 — committed to gradle-dependency-analyze/gradle-dependency-analyze by BigMichi1 2 years ago
permitAggregatorUseis not suppressing anything. it just says: all dependencies defined in this dependency are considered as used (same as adding them all one by one in the build.gradle instead of the aggregator and additionaly not warn about unused declared ones).In the example project there is now the aggregator that brings in a dependency and there is also an additional declaration for the same dependency explicitly given. the explicit definition is superfluous as it is already brought in by the aggregator.
This is why it is marked as
unusedDeclared. It would be the same when you define one dependency 2 times in the same build.gradle file, one of them is technically unused when you look at the classpath as this dependency appears twice and all classes are taken from the first jar, so the second one is unused.in your case you should remove the explicit dependency declaration and thats it.