Question

Our application uses slf4j, but has dependency to

  1. slf4j api
  2. slf4j over log4j
  3. log4j

The problem is that very often IDE imports classes from log4j and not from slf4j. Ideally, i want to have only slf4j api as a maven dependency for my application and pack slf4j binding with log4j only at the time i building a war.

I found several solutions so far:

  1. Add libs to WEB-INF/lib folder. This is bad, because i have no maven dependency control and have to store binary in my repo which is not the best thing to do.
  2. Use maven-war plugin with overlays. But as i understand adding dependency to overlay will require to declare dependency (at least as compile)

Is it ok to have only dependency for slf4j api? How to package other dependencies to war without declaring them as project dependencies?

Thanks!

Was it helpful?

Solution

Please simply specify dependency to slf4j-log4j in runtime scope.

So during compile and test time class from runtime scope will not be available. Also in IDE it shouldn't be visible - I checked it in IntelliJ.

Of course all artifacts with runtime scope will be put in WEB-INF/lib directory.

Example:

    ...
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.5</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
        <scope>runtime</scope>
    </dependency>
    ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top