maven dependency的版本冲突问题
在改造一个旧项目中,遇到各种问题。
旧项目有十多个模块,因为没有一个统一的父pom,它们对第三方的jar的版本没有统一。 虽然也存在公共的依赖模块,比如commons、util,但是,我们的模块中,有时候又会自己重复引用一些基础的、已经在公共依赖模块存在的对三方jar, 这样 就造成了很多的冲突。
当我考虑统一到一个父pom里面去的时候,发现了很多问题。
1
[ERROR]
[ERROR] The project com.wisdom:mint:1.0-SNAPSHOT (F:\dev\SVN\code\mint\pom.xml) has 1 error
[ERROR] Non-resolvable import POM: Could not transfer artifact io.netty:netty-bom:pom:3.6.10.Final from/to wisdom-public (http://192.168.1.95:8081/repository/wisdom-test67/): Failed to transfer file: http://192.168.1.95:8081/repository/wisdom-test67/io/netty/netty-bom/3.6.10.Final/netty-bom-3.6.10.Final.pom. Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 3.6.10.Final. @ org.springframework.boot:spring-boot-dependencies:2.1.0.RELEASE, C:\Users\rx63\.m2\repository\org\springframework\boot\spring-boot-dependencies\2.1.0.RELEASE\spring-boot-dependencies-2.1.0.RELEASE.pom, line 988, column 25 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
3.6.10.Final.是什么东东,发现是 子模块中写死的一个 property, 虽然没有在 dependency中使用它,但是它却生效了,真是神奇了。 大概是它把 spring-boot 的同名的 property 覆盖了吧, 但是 spring-boot 的当前版本依赖的netty 并不是 3.6.10.Final., 所以就出现了这个问题。
怎么解决: 把3.6.10.Final. 的property 删除掉就好了。不过呢,“SNAPSHOT does not allow version” 是啥? 搞不懂
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project mint: Could not resolve dependencies for project com.wisdom:mint:jar:1.0-SNAPSHOT: Failed to collect dependencies at org.springframework.boot:spring-boot-starter-web:jar:2.1.0.RELEASE -> org.hibernate.validator:hibernate-validator:jar:5.4.1.Final: Failed to read artifact descriptor for org.hibernate.validator:hibernate-validator:jar:5.4.1.Final: Could not transfer artifact org.hibernate.validator:hibernate-validator:pom:5.4.1.Final from/to wisdom-public (http://192.168.1.95:8081/repository/wisdom-test67/): Failed to transfer file: http://192.168.1.95:8081/repository/wisdom-test67/org/hibernate/validator/hibernate-validator/5.4.1.Final/hibernate-validator-5.4.1.Final.pom. Return code is: 400 , ReasonPhrase:Repository version policy: SNAPSHOT does not allow version: 5.4.1.Final. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
同上的原因。
2
[WARNING] Found duplicate and different resources in [org.springframework.data:spring-data-commons:1.13.17.RELEASE, org.springframework.data:spring-data-keyvalue:1.2.17.RELEASE, org.springframework.data:spring-data-redis:1.8.17.RELEASE]:
[WARNING] changelog.txt
...
[WARNING] Found duplicate classes/resources in test classpath.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.474 s
[INFO] Finished at: 2019-02-22T15:19:00+08:00
[INFO] Final Memory: 44M/418M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.basepom.maven:duplicate-finder-maven-plugin:1.2.1:check (duplicate-dependencies) on project mint: Found duplicate classes/resources! -> [Help 1]
一个changelog.txt 竟然引起了duplicate classes/resources问题,而且导致了编译错误。没有办法,只有把 相关的重复的jar 依赖去掉。去掉就好了。
经过仔细查找,发现 spring-boot-starters-1.5.18 依赖了duplicate-finder-maven-plugin:
C:\Users\rx63\.m2\repository\org\springframework\boot\spring-boot-starters\1.5.18.RELEASE\spring-boot-starters-1.5.18.RELEASE.pom
<plugin>
<groupId>org.basepom.maven</groupId>
<artifactId>duplicate-finder-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>duplicate-dependencies</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<failBuildInCaseOfConflict>true</failBuildInCaseOfConflict>
</configuration>
</execution>
</executions>
</plugin>
3
还遇到各种神奇问题,format 也有问题。
[ERROR] Failed to execute goal io.spring.javaformat:spring-javaformat-maven-plugin:0.0.6:validate (default) on project wisteria-api: Formatting violations found in the following files:
[ERROR] * F:\dev\SVN\code\wisteria\wisteria-api\src\main\java\com\wisdom\wisteria\constants\search\TradeSearch.java
[ERROR] * F:\dev\SVN\code\wisteria\wisteria-api\src\main\java\com\wisdom\wisteria\trade\service\AccountTradeService.java
[ERROR]
[ERROR] Run `spring-javaformat:apply` to fix.
[ERROR] -> [Help 1]
经过仔细查找,发现spring-boot-parent-1.5.18 依赖了spring-javaformat-maven-plugin:
C:/Users/rx63/.m2/repository/org/springframework/boot/spring-boot-parent/1.5.18.RELEASE/spring-boot-parent-1.5.18.RELEASE.pom
<plugin>
<groupId>io.spring.javaformat</groupId>
<artifactId>spring-javaformat-maven-plugin</artifactId>
<version>${spring-javaformat.version}</version>
<executions>
<execution>
<phase>validate</phase>
<configuration>
<skip>${disable.checks}</skip>
</configuration>
<goals>
<goal>validate</goal>
</goals>
</execution>
</executions>
</plugin>
按照提示,执行下面的 命令 就好了:
mvn spring-javaformat:apply
javaformat这个插件真是烦人,只能接受tab作为缩进,4个空格等是不能通过validate的(我尝试通过IDEA对代码进行reformat,结果,这样的代码竟然都不能通过),
后面又做了对比,发现 spring-boot-1.5.18 这个版本真是奇葩,只有它是有duplicate-finder、 spring-javaformat 这些功能,其他的版本都没有的!!
4
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce-rules) @ cactus-provider ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.BannedDependencies failed with message:
Found Banned Dependency: commons-logging:commons-logging:jar:1.1.1
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[WARNING] Found duplicate (but equal) classes in [org.apache.tomcat.embed:tomcat-embed-core:8.5.35, org.apache.tomcat:tomcat-juli:8.5.35]:
commons-logging:commons-logging:jar:1.1.1 被Banned 了 ?? 不是很好理解,暂时把commons-logging 依赖去掉吧, 纳入exclusion 之后就好了!
maven dependency的版本冲突问题的更多相关文章
- Maven 3-Maven依赖版本冲突的分析及解决小结 (阿里,美团,京东面试)
举例A依赖于B及C,而B又依赖于X.Y,而C依赖于X.M,则A除引B及C的依赖包下,还会引入X,Y,M的依赖包(一般情况下了,Maven可通过<scope>等若干种方式控制传递依赖).这里 ...
- Maven 3-Maven依赖版本冲突的分析及解决小结
我自己遇到了一个问题: 我需要使用一个api,这个api已经引入包:slf4j-log4j12 所以,在自己的pom中,如果引入了这个包,需要exclude掉: 因为在pom.xml中查询是找不到的, ...
- 11:如何解决Maven的Jar版本冲突问题
右键 Exclude,排除冲突包
- maven exclusion 解决maven传递依赖中的版本冲突
传递依赖是maven最有特色的.最为方便的优点之一,可以省了很多配置.如a 依赖 b,b 依赖c 默认 a也会依赖 c.但是也会带来隐患,如版本冲突.当然maven也考虑到解决办法,可以使用exclu ...
- maven 检查依赖冲突和版本冲突
maven 检查依赖冲突和版本冲突 在项目发布的时候,一般都需要进行依赖冲突检查或者重复类的检查,这个时候我一般会使用下面的两个命令: 1 2 3 mvn -U clean package - ...
- Maven 项目 无缘无故报错:版本冲突,其他机器上正常-提交的时候报冲突怎么也解决不掉
2018年: maven突然之间报错了,显示版本冲突,但是其他的机器是好的, 使用命令:mvn compile -P dev -e; 看看测试环境有没有问题,还是有问题.而且,刚开始只是报错:erro ...
- spring maven项目解决依赖jar包版本冲突方案
引入:http://blog.csdn.net/sanzhongguren/article/details/71191290 在spring reference中提到一个解决spring jar包之间 ...
- Maven依赖版本冲突的分析及解决小结
1:前言 做软件开发这几年遇到了许多的问题,也总结了一些问题的解决之道,之后慢慢的再遇到的都是一些重复性的问题了,当然,还有一些自己没有完全弄明白的问题.如果做的事情是重复的,遇到重复性问题的概率也就 ...
- 施用 maven shade plugin 解决 jar 或类的多版本冲突
施用 maven shade plugin 解决 jar 或类的多版本冲突 使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...
随机推荐
- Spring(转载一)
学习过Spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的,今天和大家 ...
- 5. Web vulnerability scanners (网页漏洞扫描器 20个)
5. Web vulnerability scanners (网页漏洞扫描器 20个) Burp Suite是攻击Web应用程序的集成平台. 它包含各种工具,它们之间有许多接口,旨在方便和加快攻击应用 ...
- Linux第十一节课学习笔记
区域就是firewalld预先准备了几套防火墙策略集合(策略模板),用户可以根据生产场景的不同而选择合适的策略集合,从而实现防火墙策略之间的快速切换. RUNTIME模式:当前生效,重启失效:PERM ...
- iptables工作常用操作
正确的设置iptables命令汇总 iptables -P INPUT ACCEPT iptables -F iptables -X iptables -Z iptables -I INPUT -p ...
- YOLO理解
一.YOLO v1 1.网络结构 (1)最后一层使用线性激活函数: (2)其他各层使用leaky ReLU的激活函数: 2.Training (1) 将原图划分为SxS的网格.如果一个目标的中心落入某 ...
- 【java】内部类
内部类:将一个类定义在另一个类里.对里面的那个类就是内部类. 访问特点: 1.内部类可以直接访问外部类的成员,包括私有.之所以可以直接访问外部类中的成员,是因为内部类中持有了一个外部的引用,格式 外部 ...
- 创建postgresql表空间
mkdir -p /data/pg_data/tsp sudo chown -R postgres:postgres /data/pg_data/tsp 用下面的命令断开其它的链接 登陆服务器psql ...
- 黄聪:如何正确在Vue框架里使用Swiper
实例: 错误(无法显示出分页器按钮,此功能不适用与for循环出来的图片,只有当该页面图片固定几张时能正常用) 第一步: 安装 npm i swiper (vue插件自带) 第二步: 在当前页面里引入 ...
- Java Swing 界面中文乱码问题解决(Idea环境)
编译(build)的时候和运行的时候使用同样的字符集就可以了.这里,我都设置为“UTF-8”.具体做当如下: File->Settings->Build...->Compiler,在 ...
- docker创建image
=========================================================================在已有image基础上创建一个image======= ...