https://kotlinlang.org logo
#scripting
Title
# scripting
r

ribesg

11/24/2023, 10:58 AM
I've not used my scripts in some time, I just updated them and now they no longer work. I get this error every time:
Copy code
java.lang.NoSuchMethodError: 'void org.slf4j.Logger.info(java.lang.String, java.lang.Throwable)'
They all rely on API clients that use SLF4J for logging. Anyone knows why SLF4J would no longer work in scripts? I changed dependencies versions (Kotlin, Ktor, etc.) but my code didn't change If I put my script code in a normal Gradle Kotlin project with the same dependencies it runs fine. This script fails on the second logger call:
Copy code
#!/usr/bin/env kotlin

@file:Repository(
    "<https://my-repository>",
    options = ["username=my-repository", "password=my-repository"],
)

@file:DependsOn("my:log-jvm:42")

import my.log.Log
import org.slf4j.LoggerFactory

LoggerFactory.getLogger("Tmp").info("Hello World!")
Log("Tmp").info("Hello World!")
Copy code
[main] INFO Tmp - Hello World!
java.lang.NoSuchMethodError: 'void org.slf4j.Logger.info(java.lang.String, java.lang.Throwable)'
But this code runs fine in a single kotlin JVM Gradle project with one dependency (the exact same one):
Copy code
import my.log.Log
import org.slf4j.LoggerFactory

fun main() {
    LoggerFactory.getLogger("Tmp").info("Hello World!")
    Log("Tmp").info("Hello World!")
}
Copy code
[main] INFO Tmp - Hello World!
[main] INFO Tmp - Hello World!
This does not work either
Copy code
#!/usr/bin/env kotlin

@file:Repository(
    "<https://my-repository>",
    options = ["username=my-repository", "password=my-repository"],
)

@file:DependsOn("my:log-jvm:42")
@file:DependsOn("org.slf4j:slf4j-api:2.0.9")
@file:DependsOn("org.slf4j:slf4j-simple:2.0.9")

import my.log.Log
import org.slf4j.LoggerFactory

LoggerFactory.getLogger("Tmp").info("Hello World!")
Log("Tmp").info("Hello World!")
For future reference: using sdkman, I upgraded from Gradle 8.3 to Gradle 8.5, from Kotlin 1.9.10 to Kotlin 1.9.21 and from JDK 17.0.8.1 to JDK 17.0.9, and the issue seems to be resolved
👍 1
4 Views