包含不同版本的库,在maven依赖中完全破坏了我的构建

时间:2013-05-12 18:10:01

标签: maven jackson versioning spring-social

所以我有

 <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-jaxrs</artifactId>
            <version>1.8.3</version>
            <scope>${defaultScope}</scope>
        </dependency>

我包含了这个

   <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-web</artifactId>
            <version>1.0.2.RELEASE</version>
        </dependency>

本身包含此

 <dependency>
      <groupId>org.codehaus.jackson</groupId>
      <artifactId>jackson-mapper-asl</artifactId>
      <version>1.9.3</version>
      <scope>test</scope>
    </dependency>

导致jsonwrapper找不到类。

我更新了原始版本的jackson依赖项,使其与spring-social包含的版本保持同步,现在可以使用了。

这看起来相当脆弱/不友好,我应该做些什么来避免这些问题?

2 个答案:

答案 0 :(得分:1)

您可以使用

检查依赖项的依赖项
mvn dependency:tree -Dverbose

在你的情况下它是yelds:

+- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
|  +- org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile
|  \- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.3:compile
|     \- (org.codehaus.jackson:jackson-core-asl:jar:1.8.3:compile - omitted for duplicate)
\- org.springframework.social:spring-social-web:jar:1.0.2.RELEASE:compile
   +- org.springframework:spring-webmvc:jar:3.1.0.RELEASE:compile
   |  +- org.springframework:spring-asm:jar:3.1.0.RELEASE:compile
   |  +- org.springframework:spring-beans:jar:3.1.0.RELEASE:compile
   |  |  \- (org.springframework:spring-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  +- org.springframework:spring-context:jar:3.1.0.RELEASE:compile
   |  |  +- org.springframework:spring-aop:jar:3.1.0.RELEASE:compile
   |  |  |  +- (aopalliance:aopalliance:jar:1.0:compile - omitted for duplicate)
   |  |  |  +- (org.springframework:spring-asm:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  |  +- (org.springframework:spring-beans:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  |  \- (org.springframework:spring-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  +- (org.springframework:spring-beans:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  +- (org.springframework:spring-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  +- (org.springframework:spring-expression:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  \- (org.springframework:spring-asm:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  +- org.springframework:spring-context-support:jar:3.1.0.RELEASE:compile
   |  |  +- (org.springframework:spring-beans:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  +- (org.springframework:spring-context:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  \- (org.springframework:spring-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  +- org.springframework:spring-core:jar:3.1.0.RELEASE:compile
   |  |  +- (org.springframework:spring-asm:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
   |  +- org.springframework:spring-expression:jar:3.1.0.RELEASE:compile
   |  |  \- (org.springframework:spring-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  \- (org.springframework:spring-web:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   +- javax.inject:javax.inject:jar:1:compile
   +- org.springframework:spring-web:jar:3.1.0.RELEASE:compile
   |  +- aopalliance:aopalliance:jar:1.0:compile
   |  +- (org.springframework:spring-beans:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  +- (org.springframework:spring-context:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   |  \- (org.springframework:spring-core:jar:3.1.0.RELEASE:compile - omitted for duplicate)
   \- org.springframework.social:spring-social-core:jar:1.0.2.RELEASE:compile
      \- (org.springframework:spring-web:jar:3.1.0.RELEASE:compile - omitted for duplicate)

据我所知,spring-social-web不包括jackson-mapper-asl

答案 1 :(得分:0)

您可以使用<exclusions>部分告诉Maven忽略传递依赖:

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-web</artifactId>
    <version>1.0.2.RELEASE</version>
    <exclusions>
        <exclusion>
            <artifactId>org.codehaus.jackson</artifactId>
            <groupId>jackson-mapper-asl</groupId>
        </exclusion>
    </exclusions>
</dependency>

使用此定义,Maven将仅使用您之前定义的依赖项(1.8.3版本)。但请注意,有时这会导致其他问题,例如spring-social-web可能会使用1.8.3版本中不存在的功能。