https://kotlinlang.org logo
#datascience
Title
# datascience
a

Andrew

03/29/2023, 6:17 PM
Question / issue using kotlin notebooks with local multi-project library code that uses java logging libraries I'm trying to use kotlin notebooks in tandem with my own local library code. However, I have logback and log4j deeply embedded in the local library code I am using and it is preventing me from running any of my own code in the kotlin notebook. I am wondering if there is anything obvious I am missing about setting up here that will fix this. If not, I can put together a minimum reproducible example to try and debug this. The java logging libraries I am using are as follows:
Copy code
@file:DependsOn("ch.qos.logback:logback-classic:1.4.5")
@file:DependsOn("org.slf4j:log4j-over-slf4j:2.0.3")
@file:DependsOn("org.slf4j:slf4j-api:2.0.3")
I am trying to instantiate a single class that prints out a log message when it is created, which leads to the following error stack trace:
Copy code
Could not initialize class com.smartnews.cg.logging.SnMarker
java.lang.NoClassDefFoundError: Could not initialize class com.smartnews.cg.logging.SnMarker
	at com.smartnews.cg.logging.WithLogger.<init>(WithLogger.kt:10)
	at com.smartnews.cg.helpers.DataDownloadHelper.<init>(DataDownloadHelper.kt:26)
	at Line_4_jupyter.<init>(Line_4.jupyter.kts:33)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:105)
	at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke$suspendImpl(BasicJvmScriptEvaluator.kt:47)
	at kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke(BasicJvmScriptEvaluator.kt)
	at kotlin.script.experimental.jvm.BasicJvmReplEvaluator.eval(BasicJvmReplEvaluator.kt:49)
	at org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl$eval$resultWithDiagnostics$1.invokeSuspend(InternalEvaluatorImpl.kt:103)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
I am using the latest version of IntelliJ IDEA Ultimate along with the kotlin notebook plugin (installed these yesterday). The notebook functions properly using code that is not from my local library. I am using kotlin version
1.8.10
. I've also tried using various combinations of
@file:DependsOn
or trying to import the missing classes, but have not had any luck. I'd really like to get this working so I can start using kotlin instead of python for my data wrangling needs! Thank you for your time and let me know if I can provide any additional information to help (such as a minimum reproducible example)
i

Ilya Muradyan

03/29/2023, 6:41 PM
a

Andrew

03/29/2023, 6:45 PM
image.png
i

Ilya Muradyan

03/29/2023, 6:52 PM
Interesting, it should we work then. Could you please send we the contents of Kotlin Notebook console (it's a tool window that opens when you execute the notebook)?
Or better attach to the issue (maybe with jetbrains-team visibility)
a

Andrew

03/29/2023, 6:56 PM
the issue you linked above? or meaning I should submit a brand new issue?
i

Ilya Muradyan

03/29/2023, 6:57 PM
No, the issue above is the same as I can see
a

Andrew

03/29/2023, 7:09 PM
I commented there...but hadn't logged in when I commented, so I don't think I can see the comment anymore haha :x
I believe I gave you visibility, along with the rest of the notebook team
i

Ilya Muradyan

03/29/2023, 7:15 PM
That's strange that the libraries from your project were not actually added.. I hope however that I know how to workaround this problem for now 1. Disable "Build project" and "Add libraries" options 2. Restart IDEA 3. Execute the following code in a single cell
Copy code
@file:DependsOn("ch.qos.logback:logback-classic:1.4.5")
@file:DependsOn("org.slf4j:log4j-over-slf4j:2.0.3")
@file:DependsOn("org.slf4j:slf4j-api:2.0.3")

@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-reproduction/build/classes/kotlin/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-reproduction/build/resources/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-reproduction/build/classes/java/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-reproduction/build/classes/kotlin/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-reproduction/build/resources/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-common/build/classes/kotlin/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-common/build/resources/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-common/build/classes/java/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-common/build/classes/kotlin/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-common/build/resources/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-example/build/classes/kotlin/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-example/build/resources/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-example/build/classes/kotlin/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-example/build/resources/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-inventory/build/classes/kotlin/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-inventory/build/resources/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-inventory/build/classes/kotlin/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-inventory/build/resources/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-ds/build/classes/kotlin/test")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-ds/build/classes/kotlin/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-ds/build/resources/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-experimental/build/classes/kotlin/main")
@file:DependsOn("/home/andrew/smartnews/sn-dummy-external-cg/sn-news-us-local-cg-experimental/build/resources/main")
4. Try to work with the notebook as usual
Let me know if it works or not
a

Andrew

03/29/2023, 7:19 PM
so I think that certainly helped - I am now getting an error for a different missing transitive dependency, I suppose I should just add to the
@file:DependsOn
with each of these until it "hopefully" works?
i

Ilya Muradyan

03/29/2023, 7:21 PM
Yes, I think so. Sorry, I know it's very inconvenient but experience should become much better in the next release
a

Andrew

03/29/2023, 7:22 PM
yes this totally works - for anyone else reading this in the future - it's important to keep restarting the kernel and adding the transitive dependencies to the top of the script posted above by @Ilya Muradyan
I'm happy you were able to help me get this working and unstuck myself in the future, thanks!
139 Views