0

I have a standalone maven project, let's call it foo-lib.jar, which depends on slf4j-api.jar

  1. Another project bar-app.jar depends on
    • foo-lib.jar
    • a bunch of other libraries
    • slf4j-api.jar
    • the log4j backend for SLF4j
  2. The foo-lib.jar project can be built and run standalone, and it includes an additional runtime dependency
    • slf4j-jdk14.jar

My question is: how can I declare this runtime dependency for slf4j-jdk14.jar without forcing it on the bar-app.jar project? (which maven scope should I use)

(It's also hard for me to test the effect of this on bar-app.jar; the bar-app.jar project is complicated and for some reason it doesn't build on my machine, so instead I work with that project's maintainers.)

I've read these other SO questions but it is still confusing for me.

Community
  • 1
  • 1
Jason S
  • 184,598
  • 164
  • 608
  • 970
  • 1
    You can use the concept of optional dependencies, please refer to the linked question. It means adding `true` to the dependency on `slf4j-jdk14` inside `foo-lib`. – Tunaki Jun 30 '16 at 19:02
  • does this work with `runtime`? (why would you ever use it with compile-time scope anyway? compile-time dependencies are always transitive... oh wait, no they're not. Project A class `AFoo` could have a compile time dependency on Project B interface `Bar` with an optional runtime dependency on Project B class `BarImpl`, which in turn has a compile time dependency on Project C class `Baz`. So A depends on B and B depends on C but A doesn't necessarily depend on C.) – Jason S Jun 30 '16 at 19:06
  • Yep, you can use it with `runtime`. It will have the same effect as `compile` really because its only goal is to say: "whoever is depending on me doesn't always need that dependency so don't consider it when resolving transitive dependencies". – Tunaki Jun 30 '16 at 19:12

0 Answers0