問題描述
在 Maven 依賴項中包含不同版本的庫,完全破壞了我的構建 (Including a different version of a library, in a maven dependency totally broke my build)
So I had
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson‑jaxrs</artifactId>
<version>1.8.3</version>
<scope>${defaultScope}</scope>
</dependency>
I included this
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring‑social‑web</artifactId>
<version>1.0.2.RELEASE</version>
</dependency>
which itself includes this
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson‑mapper‑asl</artifactId>
<version>1.9.3</version>
<scope>test</scope>
</dependency>
Which resulted in a no class not found for jsonwrapper.
I updated my original version of jackson dependency to be up‑to‑date with the spring‑social included version, and it now works.
This seem rather fragile/unfriendly, is there something I should be doing to avoid such problems ?
參考解法
方法 1:
You can inspect the dependencies of dependencies using
mvn dependency:tree ‑Dverbose
In your case it 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)
And as far as I see, it's not spring‑social‑web
that includes jackson‑mapper‑asl
方法 2:
You can tell Maven to ignore transitive dependencies using <exclusions>
section:
<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>
With this definition Maven will use only dependency that you defined earlier (1.8.3 version). But be aware that sometimes this can lead to other problems, for example spring‑social‑web may use features that do not exist in 1.8.3 version.
(by NimChimpsky、rzymek、hoaz)