-1

I've built a jar that uses Log4J. Now I reference this jar in another jar but in Eclipse I receive the error

The type org.apache.logging.log4j.Logger cannot be resolved. It is indirectly referenced from required .class files

If I had the Log4J dependency in the second jar all works fine but is not what I expect. I expect to receive the dependency from the first jar.

What am I doing wrong?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 1
    share both your first and second project's pom.xml dependencies – Naman Aug 26 '17 at 11:45
  • First jar has log4j org.apache.logging.log4j log4j-core 2.8.2 Second jar has first jar it.sined util system 0.0.1 c:\Development\lib\util-0.0.1.jar What I expect, like it happens for log4j in first jar, is that I put dep on log4j and maven know from log4j what else is necessary. I can't do it with my first jar. – Mirko Golfieri Aug 28 '17 at 05:20

1 Answers1

0

The jar that uses log4j directly should have the dependency in it's POM.

Jonathan Rosenne
  • 2,159
  • 17
  • 27
  • *Any* jar that uses log4j should have a dependency in its POM. That is probably more obvious and there will not be any duplicates because Maven is smart enough. Also, the jar that uses the first jar, should have the dependency on this first jar in its POM - only that way all of the dependencies of the first jar will be resolved in the second jar. – Sam Aug 26 '17 at 12:52
  • Maven supports transitive dependency so the log4j dependency is needed only for the jar that is directly dependent on it. – Jonathan Rosenne Sep 08 '17 at 07:30
  • you don't have to keep track of transitive dependencies. You can just include everything you need, Maven will not create duplicates because it, indeed, supports transitive dependencies. That's what I said – Sam Sep 08 '17 at 07:54