带有 Gradle 插件的 Findbugs 在 Java 9 中不起作用

Findbugs with Gradle plugin doesn't work in Java 9

我正在将我的项目(Gradle 中的多个项目)从 Java 8 迁移到 Java 9(到目前为止还没有使用模块)。我使用 Gradle 4.3 和 Findbugs Gradle 插件 - 我的 gradle.build 文件中有 apply plugin: 'findbugs'。在依赖项中我有

compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
compile group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'

以前用java 8open-jdk)一切正常,但是当我用java 9oracle - build 9.0.1+11)时,执行[=后出现以下异常21=](com.example.custom.MyClass 是来自我的代码库的 class): 分析时出现以下错误:

Error scanning com/example/custom/MyClass for referenced classes
java.lang.IllegalArgumentException
  At org.objectweb.asm.ClassReader.<init>(ClassReader.java:170)
  At org.objectweb.asm.ClassReader.<init>(ClassReader.java:153)
  At edu.umd.cs.findbugs.asm.FBClassReader.<init>(FBClassReader.java:35)
  At edu.umd.cs.findbugs.classfile.engine.asm.ClassReaderAnalysisEngine.analyze(ClassReaderAnalysisEngine.java:48)
  At edu.umd.cs.findbugs.classfile.engine.asm.ClassReaderAnalysisEngine.analyze(ClassReaderAnalysisEngine.java:34)
  At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getClassAnalysis(AnalysisCache.java:262)
  At edu.umd.cs.findbugs.classfile.engine.ClassInfoAnalysisEngine.analyze(ClassInfoAnalysisEngine.java:75)
  At edu.umd.cs.findbugs.classfile.engine.ClassInfoAnalysisEngine.analyze(ClassInfoAnalysisEngine.java:38)
  At edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getClassAnalysis(AnalysisCache.java:262)
  At edu.umd.cs.findbugs.FindBugs2.buildReferencedClassSet(FindBugs2.java:774)
  At edu.umd.cs.findbugs.FindBugs2.execute(FindBugs2.java:222)
  At org.gradle.api.plugins.quality.internal.findbugs.FindBugsExecuter.runFindbugs(FindBugsExecuter.java:39)
  At java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  At java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  At java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  At java.base/java.lang.reflect.Method.invoke(Method.java:564)
  At org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:100)
  At org.gradle.process.internal.worker.request.WorkerAction.runThenStop(WorkerAction.java:83)
  At java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  At java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  At java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  At java.base/java.lang.reflect.Method.invoke(Method.java:564)
  At org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
  At org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
  At org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:146)
  At org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:128)
  At org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
  At org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
  At org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
  At java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
  At java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
  At org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
  At java.base/java.lang.Thread.run(Thread.java:844)

我的 gradle 项目中的每个 class(以及 Hibernate JPA 2 元模型生成器生成的每个 class)都会出现这种情况。 我想这将与拼图模块有关。但是我没有声明任何 module-info.java,所以我猜想为整个代码库创建了一个自动模块,并且可以从任何地方访问所有内容。

虽然 findbugs Java9 support doesn't look moving ahead even gradually. And there are more posts about it which eventually suggests using spotbugs 而不是。

compile 'com.github.spotbugs:spotbugs:3.1.0'

你会发现这个migration guide同样有用。


您可能只是想尝试在您的项目构建中使用以下方法将 ASM 版本覆盖为 6.0:

compile 'org.ow2.asm:asm:6.0'