在改造一个旧项目中,遇到各种问题。

旧项目有十多个模块,因为没有一个统一的父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的版本冲突问题的更多相关文章

  1. Maven 3-Maven依赖版本冲突的分析及解决小结 (阿里,美团,京东面试)

    举例A依赖于B及C,而B又依赖于X.Y,而C依赖于X.M,则A除引B及C的依赖包下,还会引入X,Y,M的依赖包(一般情况下了,Maven可通过<scope>等若干种方式控制传递依赖).这里 ...

  2. Maven 3-Maven依赖版本冲突的分析及解决小结

    我自己遇到了一个问题: 我需要使用一个api,这个api已经引入包:slf4j-log4j12 所以,在自己的pom中,如果引入了这个包,需要exclude掉: 因为在pom.xml中查询是找不到的, ...

  3. 11:如何解决Maven的Jar版本冲突问题

    右键 Exclude,排除冲突包

  4. maven exclusion 解决maven传递依赖中的版本冲突

    传递依赖是maven最有特色的.最为方便的优点之一,可以省了很多配置.如a 依赖 b,b 依赖c 默认 a也会依赖 c.但是也会带来隐患,如版本冲突.当然maven也考虑到解决办法,可以使用exclu ...

  5. maven 检查依赖冲突和版本冲突

    maven 检查依赖冲突和版本冲突   在项目发布的时候,一般都需要进行依赖冲突检查或者重复类的检查,这个时候我一般会使用下面的两个命令:   1 2 3 mvn -U clean package - ...

  6. Maven 项目 无缘无故报错:版本冲突,其他机器上正常-提交的时候报冲突怎么也解决不掉

    2018年: maven突然之间报错了,显示版本冲突,但是其他的机器是好的, 使用命令:mvn compile -P dev -e; 看看测试环境有没有问题,还是有问题.而且,刚开始只是报错:erro ...

  7. spring maven项目解决依赖jar包版本冲突方案

    引入:http://blog.csdn.net/sanzhongguren/article/details/71191290 在spring reference中提到一个解决spring jar包之间 ...

  8. Maven依赖版本冲突的分析及解决小结

    1:前言 做软件开发这几年遇到了许多的问题,也总结了一些问题的解决之道,之后慢慢的再遇到的都是一些重复性的问题了,当然,还有一些自己没有完全弄明白的问题.如果做的事情是重复的,遇到重复性问题的概率也就 ...

  9. 施用 maven shade plugin 解决 jar 或类的多版本冲突

    施用 maven shade plugin 解决 jar 或类的多版本冲突   使用 maven shade plugin 解决 jar 或类的多版本冲突java 应用经常会碰到的依赖的三方库出现版本 ...

随机推荐

  1. C#编写CLR函数

    本案例在VS2017环境中开发: 1.新建项目,“数据库项目”,添加 UserDefinedFunctions.cs类文件,代码如下: using System; using System.Data; ...

  2. LDAP&it's usage

    LDAP: 的英文全称是Lightweight Directory Access Protocol,简称为LDAP.LDAP是轻量目录访问协议[1],它是基于X.500标准的,但是简单多了并且可以根据 ...

  3. [删括号][判断可行性的dp]

    链接:https://ac.nowcoder.com/acm/problem/21303来源:牛客网题目描述 给你一个合法的括号序列s1,每次你可以删除一个"()" 你可以删除0个 ...

  4. css3的特性

    增加了媒体查询.圆角边框.过渡动画效果

  5. MySQL必知必会 前10章学习笔记

    1. 在使用用户名和密码登陆MySQL数据库之后,首先需要指定你将要操作的数据库 USE $数据库名称 2. 使用SHOW 命令可以查看数据库和表中的信息 SHOW DATABASES; #列出可用数 ...

  6. Windows 10的最新版1803版本ISO下载

    Windows 10推出已经有几年时间了,笔者一直在用这个新版本.据说Windows 10以后只会推出新的更新,而不会有新的操作系统推出,所以Windows 10的更新就显得重要了.这次给大家推荐一个 ...

  7. Ubuntu上的MySQL可以远程访问

    1. 3306端口是不是没有打开? 使用nestat命令查看3306端口状态: ~# netstat -an | grep 3306 tcp        0      0 127.0.0.1:330 ...

  8. HTTPS SSL & TLS

    HTTPS (HTTP Secure) is an adaptation of the Hypertext Transfer Protocol (HTTP) for secure communicat ...

  9. sed命令的基本使用方法

    sed命令 stream editor,用程序的方式编辑文本.基本上是玩正则模式匹配. 用s命令替换 $ sed "s/my/Hao Chen's/g" pets.txt 单引号去 ...

  10. close_wait状态和time_wait状态(TCP连接)

    1.CLOSE_WAIT的简单解决方案 不久前,我的Socket Client程序遇到了一个非常尴尬的错误.它本来应该在一个socket长连接上持续不断地向服务器发送数据,如果socket连接断开,那 ...