3

My library, call it my-util-lib, uses slf4j as the logging facade. I need a concrete slf4j binding at runtime when I use my library directly, but I don't want the binding jar to be 'inherited' when an application imports my-util-lib. I know I can declare the dependency scope as 'test' in the POM of my-util-lib to accomplish this, but then I cannot run my library directly, other than in JUnit tests. Like if I want to run a main() method from one of my util classes for some quick-n-dirty purpose or quick test. Is there a way to accomplish this? Or to force the scope of a run to 'test' when not running a JUnit test?

crig
  • 859
  • 6
  • 19
  • Perhaps I should clarify that I want to do this in eclipse. Like from a random class select Run->Run As -> Java Application and it have it run the main() method of that class, and have the slf4j binding jar on the runtime classpath. – crig May 28 '15 at 13:44

1 Answers1

2

Set

<scope>provided</scope

on the <dependency> to slf4j.

For a discussion of the values of scope, see this question: What's the difference between these Maven dependency scopes: provided/compile/system/

  • That works. But why? From the maven docs: "This scope is only available on the compilation and test classpath, and is not transitive".. It seems it would not be on the normal runtime classpath. – crig May 28 '15 at 13:53
  • @crig I've added a link to an explanation. –  May 28 '15 at 13:56
  • ok, so I guess when you 'run as java application' in eclipse, it is just using the compilation classpath, so that's why this works. Correct? – crig May 28 '15 at 14:04