How to remove SuppressFBWarnings annotations from released jar-s?
Asked Answered
B

1

11

As you might know, SuppressFBWarnings annotations are retained in the class files, but aren't needed on runtime, so FindBugs doesn't become a runtime dependency of your project. Unfortunately, those reatined annotations cause compilation warnings like this for Gradle users who use the project as dependency:

warning: Cannot find annotation method 'value()' in type
'SuppressFBWarnings': class file for
edu.umd.cs.findbugs.annotations.SuppressFBWarnings not found

Note that Maven users don't get any warnings (with the default javac configuration). But of course I can't ignore Gradle users.

So it seems I have to remove those annotations from the release builds somehow. But I can't find any existing solution, which is strange. How do others deal with this problem?

Burress answered 24/5, 2016 at 19:24 Comment(9)
Question: Can't you just declare a dependency on annotations.jar and jsr305.jar in your published POM? That would not hurt anyone and the message should be gone.Madlin
I use Gradle a lot, but interestingly have not had this problem so far. Maybe it's a local problem?Madlin
@Thomas The project is a 0-required-dependencies project for almost 15 years now (it's FreeMarker BTW), so I'm willing to take extra steps to avoid that. Though maybe adding these dependencies with "provided" scope is an option. I'm note sure yet. It's important that a version upgrade won't break any dependent projects, which might have conflicting dependencies, etc.Burress
@Thomas: As of it's a local problem, apparently it's not. I become aware of this because other Gradle users has reported it. Later I ran into this myself too though (in a project that had 0 warning policy, so upgrading the dependency broke the build). Did you have dependencies in those Gradle projects that contain SuppressFBWarnings, while the project itself wasn't dependent on FindBugs?Burress
Ok, I understand the 0-required-dependencies criterion. In that case, you will have to solve the real problem, which is why (and what component of) Gradle creates this warning. However, the FindBugs annotations dependency does not normally contribute to dependency problems, as it has been very stable and even different versions have largely the same content (at least as far as SuppressFBWarnings and other popular annotations are concerned).Madlin
I have no control over how users run Gradle. I just release the project that they depend on. As far as they are concerned, till now (before I have added those annotations) they had no warnings, and now they do have.Burress
@Burress Have you resolved this issue? I am facing it too when I try to enable fail on warning in gradle and I don't even use that annotation. It is in the third-party jar I depend on.Delsiedelsman
@Delsiedelsman I'm on the other side of the problem (I'm the dependency), so my solution won't help you. But the solution was that the build script copies the source code, does a search-and-replace to comment out the annotations, and compile from there. Quite horrible, but saves the users from the warnings.Burress
hi @Burress I have a requirement, where I need to generate multiple json (assume i have some template) and data in some text file. so input will be template name and data will be text file. could you please share any example if you have.Hughmanick
P
4

With Gradle, you can get rid of such warnings from released Jars via,

compileOnly 'com.google.code.findbugs:annotations:3.0.1'
Prosenchyma answered 31/10, 2018 at 5:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.