1

I have a spring boot project which is having runtime transitive dependency on slf4j and log4j. Because of this I am seeing slf4j multiple binding warning and then an IllegalArgumentExceptionIllegalArgumentException. You can find below entire exception message :

SLF4J: Found binding in [jar:file:/Users/pulkit/.m2/repository/com/xyz/platform/event/PlatformLibrary/1.0.1/PlatformLibrary-1.0.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/pulkit/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
[2021-03-04 08:41:59,594] INFO Kotlin reflection implementation not found at runtime, related features won't be available. (org.springframework.core.KotlinDetector)
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/Users/pulkit/.m2/repository/com/xyz/platform/event/PlatformLibrary/1.0.1/PlatformLibrary-1.0.1.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFacto

I read other answers related to same issue and tried excluding the slf4j binding from the platform library which is a private repo but I it doesn't seems to be working. Below is the exclusion block which I added in pom.xml:

<dependency>
            <groupId>com.xyz.platform.event</groupId>
            <artifactId>PlatformLibrary</artifactId>
            <version>1.0.1</version>
<exclusions>
<exclusion>
   <groupId>org.slf4j</groupId>
   <artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
</exclusion>
</exclusions>

But this doesn't seems to be working however I am able to exclude the dependency from spring-boot-starter-web which works fine though probably due to older version it doesn't take use the property logging.pattern.console anymore.

Can somebody please suggest what can be done in this case?

I could see following in dependency tree enter image description here but for private library/package I couldn't see any dependency inside it, may be because it's dependency scope is runtime.

Note: I have changed the path of repo since it is a private repo.

  • If you run `mvn dependency:tree`, where does it show those dependencies coming from? – tgdavies Mar 04 '21 at 04:12
  • It doesn't show the dependency, I think because it's scope is runtime. – Pulkit Agarwal Mar 04 '21 at 04:19
  • You should fix PlatformLibrary so that it uses actual dependencies, instead of copying its dependencies into itself. That's why your exclusions are not working. – tgdavies Mar 04 '21 at 04:23
  • @tgdavies apology I misunderstood the comment, but have updated the details in question above. Also in the project I am just including this library, not copying it's dependency that gets downloaded automatically if I run the project because of maven. – Pulkit Agarwal Mar 04 '21 at 04:27
  • Looking at the output I think that the PlatformLibrary artifact is built using the assembly plugin, so as far as maven is concerned it doesn't have any transitive dependencies. Like this: https://stackoverflow.com/a/1729094/11002 That means you can't exclude its dependencies. – tgdavies Mar 04 '21 at 04:30
  • I have access to library's source code and I could see in it's pom that they are not using such configurations. I could only see that they are using maven-compiler-plugin with source and target with value "8" but I think that will not create jar with dependency included right ? – Pulkit Agarwal Mar 04 '21 at 05:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/229489/discussion-between-pulkit-agarwal-and-tgdavies). – Pulkit Agarwal Mar 04 '21 at 05:04

0 Answers0