5

I'm developing an application (https://github.com/stirante/RuneChanger) and a library (https://github.com/stirante/lol-client-java-api) to that application. In library I use Java-WebSocket, which recently added SLF4J API. In application I have logback as a dependency, which also has SLF4J as a dependency.

While compiling application, I have errors like these:

[ERROR] the unnamed module reads package org.slf4j.spi from both slf4j.api and lol.client.java.api
[ERROR] the unnamed module reads package org.slf4j from both slf4j.api and lol.client.java.api
[ERROR] the unnamed module reads package org.slf4j.helpers from both slf4j.api and lol.client.java.api
[ERROR] the unnamed module reads package org.slf4j.event from both slf4j.api and lol.client.java.api

Full log here: https://travis-ci.org/github/stirante/RuneChanger/builds/693607053

I tried moving the dependencies in library (https://github.com/stirante/lol-client-java-api/commit/f62c31f02ace86d50546af113a94fa37f814fb98), but no luck.

How should I handle this situation?

EDIT: Temporarily I moved org.slf4j to another package and it works, but it just seems like ugly solution, since the logging probably won't work from this library.

stirante
  • 118
  • 8
  • 1
    the only cleaner way to handle this for a modular application is to ensure **either** of these expose the package for your application to read it. so you can consider marking the exclusion for `SLF4J` on any of those dependencies. the change that you've shared as the commit, at last, excludes `slf4j` from one but not another..so you can either exclude it from both(not use as a transitive dependency) and then consume the dependency directly – Naman Jun 02 '20 at 17:29
  • @Naman I tried to exclude `slf4j` from library and from `logback` in application's pom and include `slf4j` as separate dependency. Unfortunately it doesn't work like I want it to. Also after excluding `slf4j` from library and setting it as provided, the examples stopped working as well (compiles, but throws `ClassNotFoundException`) . – stirante Jun 02 '20 at 20:46
  • wasn't really suggesting the scope change with my previous comment, but what do you mean that *it doesn't work like I want it to*? does it still show compile errors or do you mean some functional behavior is unexpected? – Naman Jun 03 '20 at 01:05
  • See http://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html and http://maven.apache.org/enforcer/maven-enforcer-plugin/ – Aniket Sahrawat Jun 03 '20 at 01:45

0 Answers0