记录:
最近遇到一个问题,项目A需要使用hutool的Sha256方法,但是项目使用的hutool的5.3.1版本,没有这个方法,所以在项目内引用了hutool的5.8.5版本。
但是项目A中原本就没有引用hutool,经排查发现是项目B引用的5.3.1版本,项目A引用了项目B。
此时有三种解决办法
1、修改项目B的依赖版本,但是可能会影响其他引用到项目B的项目,所以一般不会这么做。
2、在对应的依赖引用处添加
<exclusions>
<exclusion>
<artifactId>hutool-all</artifactId>
<groupId>cn.hutool</groupId>
</exclusion>
</exclusions>
示例:
<dependency>
<groupId>com.gccloud.ctdfs</groupId>
<artifactId>ctdfs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<exclusions>
<exclusion>
<artifactId>hutool-all</artifactId>
<groupId>cn.hutool</groupId>
</exclusion>
</exclusions>
</dependency>
可手写、也可使用Maven Helper插件
3、项目同时使用了
<dependencyManagement>
<dependencies>
<dependency>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
</dependency>
</dependencies>
来管理依赖,可将项目B引用的放在下方里管理,并将新引入的hutool放在里管理