4

在我在 IntelliJ IDEA 2017.1.2(Build #IC-171.4249.39)中使用 RxJava 和 Kotlin 开发的基于 JavaFX Gradle 的应用程序中,我遇到了一个异常:

线程“JavaFX 应用程序线程”中的异常 java.lang.NoClassDefFoundError: org/reactivestreams/Publisher

每次这样的代码

return Completable.complete()

被执行。根据类似问题的建议Why I am getting NoClassDefFoundError: org/reactivestreams/Publisher,我尝试将包含反应流添加到dependencies我的build.gradle脚本块中

dependencies {
    compile 'org.jetbrains.kotlin:kotlin-stdlib:1.1.2'
    compile 'org.reactivestreams:reactive-streams:1.0.0'
    compile 'io.reactivex.rxjava2:rxkotlin:2.0.0'
}

但问题仍然存在。依赖关系树看起来像这样:

compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

compileClasspath - Compile classpath for source set 'main'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

\--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.2
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
          \--- org.jetbrains:annotations:13.0

kaptTest
\--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.2
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
          \--- org.jetbrains:annotations:13.0

runtime - Runtime dependencies for source set 'main' (deprecated, use 'runtimeOnly ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

testCompile - Dependencies for source set 'test' (deprecated, use 'testImplementation ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

testCompileClasspath - Compile classpath for source set 'test'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

testRuntime - Runtime dependencies for source set 'test' (deprecated, use 'testRuntimeOnly ' instead).
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2
|    \--- org.jetbrains:annotations:13.0
+--- org.reactivestreams:reactive-streams:1.0.0
\--- io.reactivex.rxjava2:rxkotlin:2.0.0
     +--- io.reactivex.rxjava2:rxjava:2.0.7
     |    \--- org.reactivestreams:reactive-streams:1.0.0
     \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.0 -> 1.1.2 (*)

如您所见,每个环境中都存在org.reactivestreams:reactive-streams 。

现在,我已经设法通过手动添加对reactive-streams-1.0.0.jar 的依赖来解决问题,但我根本不喜欢这个解决方案。

有人可以建议更好的解决方案吗?谢谢!

4

0 回答 0