Reputation: 3542
Our application uses slf4j, but has dependency to
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:
Is it ok to have only dependency for slf4j api? How to package other dependencies to war without declaring them as project dependencies?
Thanks!
Upvotes: 1
Views: 945
Reputation: 8557
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>
...
Upvotes: 1