0

The problem has been solved in this question.

I have a simple groove script:

@Grapes([
    @Grab(group='io.javalin', module='javalin', version='5.6.2'),
    @Grab(group='org.slf4j', module='slf4j-simple', version='2.0.7'),
    @Grab(group='com.fasterxml.jackson.core', module='jackson-databind', version='2.15.2')
])
import io.javalin.Javalin

def app = Javalin.create()
    .get("/home", ctx -> ctx.result("Home"))
    .start(7070)

When I start, I get the following warning :

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.

But if I create a project using maven, everything will work and logs will be output.

<dependency>
    <groupId>io.javalin</groupId>
    <artifactId>javalin</artifactId>
    <version>5.6.2</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>2.0.7</version>
</dependency>
import io.javalin.Javalin

static void main(String[] args) {
    def app = Javalin.create()
            .get("/home", ctx -> ctx.result("Home page"))
            .start(7070)
}

log:

[main] INFO io.javalin.Javalin - Starting Javalin ...
[main] INFO org.eclipse.jetty.server.Server - jetty-11.0.15; built: 2023-04-11T18:37:53.775Z; jvm 19.0.2+7-FR
[main] INFO org.eclipse.jetty.server.session.DefaultSessionIdManager - Session workerName=node0
[main] INFO org.eclipse.jetty.server.handler.ContextHandler - Started i.j.j.@7318daf8{/,null,AVAILABLE}

If we look into the ~\groovy\grapes cache, we will see the necessary libraries (so Grub successfully downloads these dependencies.):

.groovy/
├─ grapes/
│  ├─ slf4j-api/
│  ├─ slf4j-parent/
│  ├─ slf4j-simple/

If you try to get rid of the slf4j dependency in the script

@Grapes([
    //@Grab(group='org.slf4j', module='slf4j-simple', version='2.0.7'),
    @Grab(group='io.javalin', module='javalin', version='5.6.2'),
    @Grab(group='com.fasterxml.jackson.core', module='jackson-databind', version='2.15.2')
])

... then we will see that the warning text has changed:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.

#########################################################################
Javalin: It looks like you don't have a logger in your project.
The easiest way to fix this is to add 'slf4j-simple':

pom.xml:
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>2.0.7</version>
</dependency>

build.gradle or build.gradle.kts:
implementation("org.slf4j:slf4j-simple:2.0.7")

Visit https://javalin.io/documentation#logging if you need more help
#########################################################################

This suggests that grab downloads the slf4j-simple dependency, adds it to the classpath. Javelin sees that there is a dependency and does not issue an error, but for some reason the implementation of slf4j-simple does not work properly. What could be the reason?

upd:

If we add code to the script that outputs all jar files to classpath, then we will see slf4j there:

def printClassPath(classLoader) {
    println "$classLoader"
    classLoader.getURLs().each {url->
        println "- ${url.toString()}"
    }
    if (classLoader.parent) {
        printClassPath(classLoader.parent)
    }
}
printClassPath this.class.classLoader

** output: **

- file:/C:/Users/-/.groovy/grapes/org.slf4j/slf4j-api/jars/slf4j-api-2.0.7.jar
- file:/C:/Users/-/.groovy/grapes/org.slf4j/slf4j-simple/jars/slf4j-simple-2.0.7.jar
- file:/C:/Users/-/.groovy/grapes/org.slf4j/slf4j-api/jars/slf4j-api-2.0.7.jar
- file:/C:/Users/-/.groovy/grapes/org.slf4j/slf4j-simple/jars/slf4j-simple-2.0.7.jar
- file:/C:/Dev/Groovy/groovy-4.0.13/lib/slf4j-api-2.0.7.jar

upd/2

I tried to connect logback as an implementation, nothing has changed.

@Grapes([
        @Grab(group='org.slf4j', module='slf4j-api', version='2.0.7'),
        @Grab(group='ch.qos.logback', module='logback-classic', version='1.4.11'),
        @Grab(group = 'io.javalin', module = 'javalin', version = '5.6.2'),
        @Grab(group = 'com.fasterxml.jackson.core', module = 'jackson-databind', version = '2.15.2')
])

upd/3

I was able to fix this problem with a crutch (I don't like this solution.).

I manually placed the file slf4j-simple-2.0.7.jar in %GROOVY_HOME%\lib (in fact, I put the file inside the Groovy SDK )

upd/4

I added the import of a class from the slf4j-simple library to the script:

import org.slf4j.simple.SimpleLogger

println SimpleLogger.class

and it didn't cause an error, I got the class in the console (but the problem still remains)

class org.slf4j.simple.SimpleLogger <- class name from slf4j-simple-2.0.7.jar

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Santa Monica
  • 332
  • 3
  • 11

0 Answers0