scijava / scripting-kotlin

[EXPERIMENTAL] JSR-223-compliant Kotlin scripting plugin
http://imagej.net/Kotlin_Scripting
Other
10 stars 2 forks source link

Fix circular dependencies #8

Open hanslovsky opened 3 years ago

hanslovsky commented 3 years ago

The Fiji updater reports circular dependencies when trying to upload to ntakt updae site. Thanks to help from @ctrueden I was able to identify duplicate classes that appear both in the shaded scripting-kotlin jar and the org.jetbrains.kotlin:kotlin-script-runtime:jar:1.4.30:runtime transitive dependency. The org.jetbrains.kotlin:kotlin-compiler-embeddable:jar:1.4.30:compile dependency that pulls in this transitive dependency is marked as optional. No other dependency has kotlin-script-runtime as dependency so I am a bit confused about why kotlin-script-runtime is installed in the first place. Removing it from the shaded jar solved the issue of duplicate classes. I have yet to confirm that the Fiji updater does not report any circular dependencies after this fix.

For reference, discussion on gitter

For completeness, this is the Maven dependency tree:

org.scijava:scripting-kotlin:jar:0.1.2-SNAPSHOT
+- org.scijava:scijava-common:jar:2.83.3:compile
|  +- org.scijava:parsington:jar:2.0.0:compile
|  \- org.bushe:eventbus:jar:1.4:compile
+- org.jetbrains.kotlin:kotlin-compiler-embeddable:jar:1.4.30:compile
|  +- org.jetbrains.kotlin:kotlin-script-runtime:jar:1.4.30:runtime
|  +- org.jetbrains.kotlin:kotlin-reflect:jar:1.4.30:runtime
|  +- org.jetbrains.kotlin:kotlin-daemon-embeddable:jar:1.4.30:runtime
|  \- org.jetbrains.intellij.deps:trove4j:jar:1.0.20181211:runtime
+- org.jetbrains.kotlin:kotlin-stdlib:jar:1.4.30:compile
|  +- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.4.30:compile
|  \- org.jetbrains:annotations:jar:13.0:compile
+- org.jetbrains.kotlin:kotlin-scripting-jsr223:jar:1.4.30:compile
|  +- org.jetbrains.kotlin:kotlin-scripting-common:jar:1.4.30:runtime
|  |  \- org.jetbrains.kotlinx:kotlinx-coroutines-core:jar:1.3.8:runtime
|  +- org.jetbrains.kotlin:kotlin-scripting-jvm:jar:1.4.30:runtime
|  +- org.jetbrains.kotlin:kotlin-scripting-jvm-host:jar:1.4.30:runtime
|  \- org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:jar:1.4.30:runtime
|     \- org.jetbrains.kotlin:kotlin-scripting-compiler-impl-embeddable:jar:1.4.30:runtime
+- junit:junit:jar:4.13:test
|  \- org.hamcrest:hamcrest-core:jar:1.3:test
\- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:1.4.30:compile
   \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:1.4.30:compile

Solution

I found out that org.jetbrains.kotlin:kotlin-scripting-jsr223:jar has kotlin-compiler-embeddable as a transitive dependency with scope runtime. For some reason, this transitive dependency would only show in mvn dependency:tree when I did not have kotlin-compiler-embeddable as dependency for scripting-kotlin. In the end, the solution was to simply include kotlin-scripting-jsr233 and its transitive dependencies in the shaded jar. I tested this branch in a clean Fiji.app and distributed/ to/installed from the ntakt update site.