Maven 解决Jar包版本冲突

今天遇到一个小问题。在使用apache-commons-codec包进行编码/解码的时候,用到了Base64类的decodeBase64(String base64String)方法,这个方法在1.4版中才提供。而我们的工程中对codec存在两个间接的依赖,一个依赖1.2版本,一个依赖1.4版本,打包后,只有1.2版本,所以会报找不到该方法的错误。

这个问题其实很好解决。在依赖1.2版本的项目上,排除对codec的间接依赖即可。如:

		<dependency>
          <!-- 你直接依赖的Jar包-->
			<groupId>AAA</groupId>
			<artifactId>AAA</artifactId>
			<exclusions>
				<exclusion>
                 <!-- 你想排除的间接依赖的Jar包-->
					<artifactId>xxx</artifactId>
					<groupId>xxx</groupId>
				</exclusion>
			</exclusions>
			<version>AAA</version>
		</dependency>
Thanks a lot.