Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot suppress SpotBug warnings in generated code #27

Closed
eekboom opened this issue May 26, 2020 · 3 comments
Closed

Cannot suppress SpotBug warnings in generated code #27

eekboom opened this issue May 26, 2020 · 3 comments
Labels

Comments

@eekboom
Copy link

eekboom commented May 26, 2020

I have been fighting this for a couple of hours:
We use the mapstruct annotation processor and SpotBugs complains about code generated by that annotation processor.

I tried using "exclude", but that has no effect.

I would like to move the apt generated sources to another source set, but I don't even know if that is possible.

The docs mention that I have misconfigured my build: "If non of the above works for you, then you did sources configuration not according to best practices."

I tried using "excludeSources", but that, too, just has no effect.

Finally I tried to configure an exclusion file for SpotBugs, but probably I made a mistake, because it seems to be completely ignored.
BTW: The page in the docs at "User guide -> Configuration" has a bug, it says to use "afterEvaluation {". That should be "afterEvaluate {".

See here for an example project: https://github.com/eekboom/qualitymapstruct

@xvik
Copy link
Owner

xvik commented May 27, 2020

Good case! This is a quality plugin issue.

The root problem is that new spotbugs plugin use gradle properties instead of direct fields, which force me to do many hacks to init them early because otherwise values simply ignored (read property can't be updated and gradle read task properties too early). As a result:

  • exclusion config is always forcefully substituted (because I can't read property to look if there already custom value - properly would be locked)
  • exclusion logic applied too early (because spotbugs task property gets evaluated too early) and no actual exclusions get registered (files not yet generated)

The only workaround for you now is to modify default exclusions file:

  1. Init configs with: gradlew initQualityConfig
  2. Remove everything in gradle/config except spotbugs/exclude.xml (default files will be used implicitly)
  3. Add your manual exclusion to exclude.xml file
<Match>
    <Source name="~.*?MapperImpl.*" />
</Match>

After that, you can remove all additional configurations in build.gradle

Issues list (to not forget):

  • Fix "afterEvaluation" in docs
  • Document the correct way of default config files override
  • Document why manually set spotbugs.excludeFilter will not work (try to support it?)
  • Fix spotbugs exclusions for generated sources (correct lifecycle) for both "exclude" and "excludeSources"

@xvik xvik added the bug label May 27, 2020
@eekboom
Copy link
Author

eekboom commented May 27, 2020

Thanks a lot for the quick reply! That workaround is fine for us.
It really would be nice if files in the default paths for generated source would be ignored.
I couldn't make that work with the spotbugs exclusions, though, because the name seems to not include the directory path. ("~.*?/generated/sources/.*" does not work.)

@xvik
Copy link
Owner

xvik commented May 27, 2020

quality.excludeSources is the only option for filtering by source location. All other exclusions are relative to source root. Someday it will work again (but not very soon - maybe a few weeks).

If possible, try to generate sources into a special package to be able to exclude an entire package with standard spotbugs exclusions file.

@xvik xvik closed this as completed in ba8243c Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants