views:

120

answers:

1

I have a project managed by maven with slf4j-api-1.5.8 and log4j-1.2.14 dependencies. In runtime , slf4j needs slf4j-log4j12-1.5.8.jar to "bridge" output to log4j.

So in pom.xml , I add this dependency :

  <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.8</version>
            <type>jar</type>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
  </dependencyManagement>

After building (war:war) , log4j-1.2.14.jar and slf4j-api-1.5.8.jar are both added to WEB-INF/lib directory , but I cannot find slf4j-log4j12-1.5.8.jar within !

I then use "Dependency Hierarchy" to check the resolved dependencies , but cannot find slf4j-log4j12 (so it's not packaged into WEB-INF/lib)

I don't know what's going wrong here ?

environment : maven 3.0-beta1 , m2-eclipse-0.10.0.20100209

+2  A: 

The dependency management section is a mechanism for centralizing dependency information, adding a dependency in the dependency management section doesn't make it a dependency of your project by itself, you still need to declare it as dependency:

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.5.8</version>
      <type>jar</type>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</dependencyManagement>
<dependencies>
  <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
  </dependency>
</dependencies>
Pascal Thivent