2

I have a new Java application that is module based. I need to pull in two dependencies (one module based - sqlite - and one that is not - commonutilities) but both contain transient dependencies to the org.slf4j package.

I know that in the pre-module era, you'd simply include an exclusion element in your pom file's dependency element to exclude the package from one of the two JARs.

Is there a similar mechanism in the module world where you can exclude a transient dependency? Or, how do I resolve this?

The error trace is:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project MonthlyFinances: Compilation failure: Compilation failure:
[ERROR] the unnamed module reads package org.slf4j.spi from both org.slf4j and CommonUtilities
[ERROR] the unnamed module reads package org.slf4j.helpers from both org.slf4j and CommonUtilities
[ERROR] the unnamed module reads package org.slf4j.event from both org.slf4j and CommonUtilities
[ERROR] the unnamed module reads package org.slf4j from both org.slf4j and CommonUtilities
[ERROR] module org.slf4j reads package org.slf4j from both CommonUtilities and org.slf4j
[ERROR] module org.slf4j reads package org.slf4j.spi from both CommonUtilities and org.slf4j
[ERROR] module org.slf4j reads package org.slf4j.helpers from both CommonUtilities and org.slf4j
[ERROR] module org.slf4j reads package org.slf4j.event from both CommonUtilities and org.slf4j
[ERROR] module org.xerial.sqlitejdbc reads package org.slf4j.spi from both org.slf4j and CommonUtilities
[ERROR] module org.xerial.sqlitejdbc reads package org.slf4j.helpers from both org.slf4j and CommonUtilities
[ERROR] module org.xerial.sqlitejdbc reads package org.slf4j.event from both org.slf4j and CommonUtilities
[ERROR] module org.xerial.sqlitejdbc reads package org.slf4j from both org.slf4j and CommonUtilities
[ERROR] module CommonUtilities reads package org.slf4j.spi from both org.slf4j and CommonUtilities
[ERROR] module CommonUtilities reads package org.slf4j.helpers from both org.slf4j and CommonUtilities
[ERROR] module CommonUtilities reads package org.slf4j.event from both org.slf4j and CommonUtilities
[ERROR] module CommonUtilities reads package org.slf4j from both org.slf4j and CommonUtilities
[ERROR] /D:/NonGitRepo/MonthlyFinances/src/main/java/module-info.java:[1,1] module org.sperbolink.monthlyfinances reads package org.slf4j from both CommonUtilities and org.slf4j
4
  • I believe the module world was introduced so you can feed both packages' needs. If they need same versions of the slf4j library just include it once. If they need different versions include both - hoping they have different package names. If that does not work out, you'd have to ensure the modules and their dependencies are loaded via different classloaders. Commented Feb 1, 2024 at 23:45
  • JPMS modules can declare optional dependencies via requires static, but that is something determined by the module at compile-time, not by the project pulling in the library. Commented Feb 2, 2024 at 0:01
  • 3
    That trace makes it seem like the "CommonUtilities" dependency has embedded SLF4J in its own JAR file (i.e., a so-called fat/uber/shadowed JAR file). That is something that should be solved by the maintainer of "CommonUtilities". Commented Feb 2, 2024 at 0:04
  • 1
    depending on the control you have on these modules, you can choose one of the approach suggested here Commented Feb 2, 2024 at 2:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.