Reputation: 1691
I use Lombok. Some time ago when building a project, the compiler started issuing the following message:
Found slf4j-api dependency but no providers were found. Did you mean to add slf4j-simple? See https://www.slf4j.org/codes.html#noProviders .
If you follow the link, there is a rather vague comment:
This warning, i.e. not an error, message is reported when no SLF4J providers could be found on the class path. Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem. Note that these providers must target slf4j-api 1.8 or later.
In the absence of a provider, SLF4J will default to a no-operation (NOP) logger provider.
Please note that slf4j-api version 1.8.x and later use the ServiceLoader mechanism. Earlier versions relied on the static binder mechanism which is no longer honored by slf4j-api. Please read the FAQ entry What has changed in SLF4J version 1.8.0? for further important details.
If you are responsible for packaging an application and do not care about logging, then placing slf4j-nop.jar on the class path of your application will get rid of this warning message. Note that embedded components such as libraries or frameworks should not declare a dependency on any SLF4J providers but only depend on slf4j-api. When a library declares a compile-time dependency on a SLF4J provider, it imposes that provider on the end-user, thus negating SLF4J's purpose.
I have no idea how to do it correctly. If you have an experience, please, explain me how to do it.
Upvotes: 53
Views: 285365
Reputation: 3468
As stated in tutorialspoint :
SLF4J stands for Simple Logging Facade for Java. It provides a simple abstraction of all the logging frameworks. It enables a user to work with any of the logging frameworks such as Log4j, Logback, JUL (java.util.logging), etc. using single dependency.
This means that you have to provide a concrete java logging library on your classpath on top of the dependency for SLF4J itself (Example with Maven):
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.16</version>
</dependency>
You will also need to specify the dependency on your preferred logging library. For instance:
For standard jdk1.4 logging :
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-jdk14 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>2.0.16</version>
<scope>runtime</scope>
</dependency>
For slf4j-simple logging :
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
<scope>runtime</scope>
</dependency>
For log4j logging :
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>2.0.16</version>
<scope>runtime</scope>
</dependency>
Upvotes: 67
Reputation: 1
In my case, I added a new library (flying-saucer-pdf) to the project and the app can't start. The issue was that this new library has a dependency with an existing library (slf4j-api) in the project (a collision). This is called "transitive dependency".
If you use gradle, in your build.gradle file you need to exclude that transitive dependency (because you already have the required library).
implementation('org.xhtmlrenderer:flying-saucer-pdf:9.5.1') {
exclude group: 'org.slf4j', module: 'slf4j-api'
}
Upvotes: 0
Reputation: 439
In my case, I'm making use of maven. All I have to do is select the 'reload all maven my projects' option from the maven menu.. This helps with full project import which include: read all config files and getting maven project model, resolve all dependencies, resolve all plugins.
Because Slf4j is an abstract class, it immediately resolves the Slf4j provider issue by supplying the necessary implementation for the slf4j (Simple Login Facade for Java) class.
Upvotes: 1
Reputation: 3432
In my case, this error was triggered from adding a new dependency: com.amazonaws:DynamoDBLocal:2.0.0+
The problem was fixed by adding exclude(group = "org.eclipse.jetty")
. As in:
testImplementation("com.amazonaws:DynamoDBLocal:2.0.0+") {
exclude(group = "org.eclipse.jetty")
}
Upvotes: 0
Reputation: 432
To disable this message from a library that depends on slf4j
, you can add slf4j-nop
to your dependencies before your library, e.g.
implementation 'org.slf4j:slf4j-nop:2.0.7'
At the time of writing, the latest version of slf4j
is 2.0.7
,
this can be checked at https://central.sonatype.com/artifact/org.slf4j/slf4j-nop
If you need output from the library you are using, you can add slf4j-simple
instead of slf4j-nop
Upvotes: 8
Reputation: 4878
You can refer to THIS
This warning, i.e. not an error, message is reported when no SLF4J providers could be found on the class path. Placing one (and only one) of the many available providers such as slf4j-nop.jar slf4j-simple.jar, slf4j-reload4j.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.
Upvotes: 1
Reputation: 31
This can be due to the version of slf4J API and you are using. try this changing the version like this.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
Upvotes: 3
Reputation: 139
Refer this Page: http://www.slf4j.org/codes.html#noProviders
You may add either of the following dependencies: Placing one (and only one) of slf4j-nop.jar slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem
I used "slf4j-simple" maven dependency from https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j
Upvotes: 4