psiegman / epublib

a java library for reading and writing epub files
http://www.siegmann.nl/epublib
1.06k stars 317 forks source link

epublib-core could avoid sl4j-simple binding #134

Open nikhilsilveira opened 4 years ago

nikhilsilveira commented 4 years ago

Using epublib-core in a springboot application causes two issues:

  1. a warning: Class Path Contains Multiple SLF4J Bindings -- this can be ignored
  2. IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

The problem seems to me, the slf4j-simple binding (provider) inherited from the parent pom. Considering the core library intention as a client, it might be better served by just using the sl4j-api and omitting the binding (provider). From baeldung:

It is worth noting that embedded components such as libraries or frameworks should never declare a dependency on any SLF4J binding. This is because when a library declares a compile-time dependency on an SLF4J binding, it imposes that binding on the end-user. Obviously, this negates SLF4J's basic purpose. Consequently, they should only depend on the slf4j-api library.

A commonly proposed solution is to add to your gradle build file:

configurations {
    all {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
        exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
    }

However, this disables logging configuration for the entire app. On the other hand, this doesn't seem to work:

    compile ('nl.siegmann.epublib:epublib-core:4.0') {
        exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
        exclude group: 'ch.qos.logback', module: 'logback-classic'
    }

The solution that worked for me was to:

Now it no longer has a conflict and spring boot logging will work as expected.