spotbugs / spotbugs-gradle-plugin

https://plugins.gradle.org/plugin/com.github.spotbugs
Apache License 2.0
180 stars 68 forks source link

Adding SpotBugs causes JavaCC to fail #70

Closed thpr closed 4 years ago

thpr commented 6 years ago

I thought I had added this back in April, but apparently not. Was sent here from this issue: https://github.com/spotbugs/spotbugs/issues/612

Add the following line to the plugins {} section in Gradle id "com.github.spotbugs" version '1.6.5'

No other changes in the gradle file, now a new task is generated: compileJavaccJava

This new task attempts to compile items not related to compileJavacc, and which are from directories that have external library dependencies that are not comprehended by the javacc source set: sourceSets { ... javacc { java { srcDirs 'code/src/javacc' } } ... }

nor by:

compileJavacc { inputDirectory = file('code/src/javacc/') outputDirectory = file('code/src/java/') }

The result is a compile failure.

The full repository with the change in place (as well as some additional spotbugs configuration that is valuable to us but not necessary to reproduce the error) can be found here: https://github.com/thpr/pcgen-formula/tree/SpotBugs

KengoTODA commented 6 years ago

Could you tell us which kind of failure it has? Is it not reasonable (e.g. generated code by JavaCC really has problem)?

thpr commented 6 years ago

It fails after hundreds of errors. Things like: "error: package pcgen.base.util does not exist" ...which is complaining about "import pcgen.base.util.TypedKey;"

The thing is, these are very real packages, and as I stated above, this all compiles without SpotBugs enabled.

This code has run well for a long time... over 100 versions over years. Those packages and classes the compileJavaccJava task are complaining about are very real in a JAR library. So these are configuration issues, not real code issues.

What is so baffling to me is that solely adding the spotbugs id line to build.gradle triggers this new task (and I can't find any documentation of what that task is or does) and thus leads to this set of failures.

So:

KengoTODA commented 6 years ago

If you think generated code is working well, you don't care this problem so heavily. I recommend you to simply exclude generated classes from the target for SpotBugs.

I feel it's one of common patterns that generated code has problem (e.g. Lombok generates logger variable w/ bad naming) and static analysis needs to ignore them.

KengoTODA commented 6 years ago

Is the compileJavaccJava task actually added by SpotBugs or is there some other side effect of adding SpotBugs that is unclear? What is compileJavaccJava doing that is needed?

compileJavaccJava is not added by SpotBugs, but added by gradle java plugin.

Does this new task try to compile code assuming it has no dependencies? If so, that is a problem...

It depends on your config. Use auxClasspath to provide path of dependencies.

thpr commented 6 years ago

If you think generated code is working well, you don't care this problem so heavily. I recommend you to simply exclude generated classes from the target for SpotBugs.

I'm still not sure we are discussing the same problem.

I am ignoring the generated code. The code which is triggering the error isn't generated code. I already have a suppressions.xml that ignores the generated code:

compileJavaccJava is not added by SpotBugs, but added by gradle java plugin.

...but where I'm confused is that Spotbugs is causing it to run. When I do a dry run without the id line for spotbugs, I get this: :compileJjtree SKIPPED :compileJavacc SKIPPED :compileJava SKIPPED :processResources SKIPPED :classes SKIPPED :jar SKIPPED :assemble SKIPPED :compileTestJava SKIPPED :processTestResources SKIPPED :testClasses SKIPPED :test SKIPPED :check SKIPPED :build SKIPPED

When I do it with the id line for spotbugs added, I get this: :compileJjtree SKIPPED :compileJavacc SKIPPED :compileJava SKIPPED :processResources SKIPPED :classes SKIPPED :jar SKIPPED :assemble SKIPPED :compileJavaccJava SKIPPED :processJavaccResources SKIPPED :javaccClasses SKIPPED :spotbugsJavacc SKIPPED :spotbugsMain SKIPPED :compileTestJava SKIPPED :processTestResources SKIPPED :testClasses SKIPPED :spotbugsTest SKIPPED :test SKIPPED :check SKIPPED :build SKIPPED

... so SpotBugs has added a number of steps (bolded), some of which are related to Javacc that are not necessary to the original build. I'm at a loss for why these were added?

thpr commented 6 years ago

adding "-x spotbugsJavacc" to my gradle command line at least gets me a workaround.

I'm still interested to know if there is a behavior/structure related to how Javacc and gradle are used that SpotBugs is expecting and not seeing in our setup.

KengoTODA commented 6 years ago

wmm, strange... I'm sure that the tasks with spotbugs prefix are generated by spotbugs-gradle-plugin, But following three tasks should come from other place.

:compileJavaccJava SKIPPED :processJavaccResources SKIPPED :javaccClasses SKIPPED

I guess they are java plugin's sourceSet tasks.

KengoTODA commented 4 years ago

I'll close this inactive issue. If you could reproduce this with the latest release, please feel free to reopen.