Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude commons logging dependency of spring with ivy?

I have a project build with ant using ivy for dependency management. I have no ivysetting file, but an ivy.xml with the following dependency (I want to use spring with slf4j instead of commons logging):

<configurations>
  <conf name="compile" />
  <conf name="runtime" extends="compile"/>
</configurations>
<dependencies>
  <dependency org="org.springframework" name="spring-webmvc" rev="3.0.5.RELEASE" conf="compile->default">
    <exclude org="commons-logging" name="commons-logging"/>
  </dependency>
  <dependency org="org.slf4j" name="slf4j-api" rev="1.6.1" conf="compile->default" />
  <dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.6.1" conf="runtime->default" />
</dependencies>

But when resolving the compile configuration, commons-logging is resolved. I also tried to use the exclude on an explicit spring-core dependency but commons-logging is always placed into the compile classpath.

What is my fault? Isn't it that what Not Using Commons Logging describes for maven? Is it an ivy bug? Need I a special setting? Has ivy something cached? Any idea?

I use ant 1.8.2 and ivy 2.2.0, Using IvyDE in Eclipse has the same problem.

like image 607
Arne Burmeister Avatar asked Jun 15 '11 21:06

Arne Burmeister


People also ask

How do you exclude Commons from logging?

To switch off commons-logging is easy: just make sure it isn't on the classpath at runtime. In Maven terms you exclude the dependency, and because of the way that the Spring dependencies are declared, you only have to do that once.

Does Spring use SLF4J?

Logging is a very important part of any application and it helps with debugging issues. Spring Boot, by default, includes spring-boot-starter-logging as a transitive dependency for the spring-boot-starter module. By default, Spring Boot includes SLF4J along with Logback implementations.

What is the spring boot starter that has to be added for logging dependency?

Spring Boot supports Log4j 2 for logging configuration if it is on the classpath. If you use the starters for assembling dependencies, you have to exclude Logback and then include log4j 2 instead. If you do not use the starters, you need to provide (at least) spring-jcl in addition to Log4j 2.

Which dependency is used for log?

In the case of logging, the only mandatory dependency is Apache Commons Logging. We need to import it only when using Spring 4.


2 Answers

Use module instead of name

<exclude org="commons-logging" module="commons-logging"/>

like image 72
Cesar Gomez Velazquez Avatar answered Oct 02 '22 13:10

Cesar Gomez Velazquez


Your usage of the <exclude /> seems to be broken for unkown reasons. I tried something similar on my pc and the following worked:
Try the top-level exclude (which is directly under <dependencies />:

    <dependencies>
      <dependency org="org.springframework" name="spring-webmvc" rev="3.0.5.RELEASE" conf="compile->default">
      </dependency>
      <dependency org="org.slf4j" name="slf4j-api" rev="1.6.1" conf="compile->default" />
      <dependency org="org.slf4j" name="jcl-over-slf4j" rev="1.6.1" conf="runtime->default" />
      <exclude org="commons-logging"/>
</dependencies>

I don't know why the other one is not working. There are some bugs in JIRA concerning exclude and circular dependencies, but that doesn't seem to fit this case. Maybe it's a real bug.

like image 21
oers Avatar answered Oct 02 '22 14:10

oers