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

旧项目有十多个模块,因为没有一个统一的父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. Navicat 连接MySQL时出现1251错误的解决方案

    我用的MySQL版本是8.0.11,比较新的MySQL版本中采用的加密方式与旧的不同,从而导致1251错误. 解决方案:打开终端连接上数据库,执行以下语句,问题解决.(自己遇到过的坑,亲测有效) US ...

  2. LeetCode 852. Peak Index in a Mountain Array C++ 解题报告

    852. Peak Index in a Mountain Array -- Easy 方法一:二分查找 int peakIndexInMountainArray(vector<int>& ...

  3. hibernate的lazy初始化结果

    package com.ehcache; import java.io.Serializable; public class User implements Serializable{ private ...

  4. HNOI2006公路修建问题

    https://www.luogu.org/problemnew/show/P2323 [题目描述] OI island是一个非常漂亮的岛屿,自开发以来,到这儿来旅游的人很多.然而,由于该岛屿刚刚开发 ...

  5. 【java编程】java的关键字修饰符

    一.transient java语言的关键字,变量修饰符,如果用transient声明一个实例变量,当对象存储时,它的值不需要维持.换句话来说就是,用transient关键字标记的成员变量不参与序列化 ...

  6. JS ajax请求参数格式( formData 、serialize)

    $("#importBtn").click(function(){ if($("#conId").val() == ""){ alert(& ...

  7. docker nginx letsencrypt

    https越来越流行了,但免费的证书一般是一年有效期.一般是够用了,但懒人都想一劳永逸, 有个免费证书颁发机构是letsencrypt.它是开源,并且完全免费的,它颁发的证书已经被几乎所有的浏览器所认 ...

  8. python中使用 C 类型的数组以及ctypes 的用法

    Python 在 ctypes 中为我们提供了类似C语言的数据类型, 它的用途(我理解的)可能是: (1) 与 其他语言(如 C.Delphi 等)写的动态连接库DLL 进行交换数据,因为 pytho ...

  9. ORACLE数据库自动备份压缩的批处理脚本 rar 7z

    使用7z的版本: @echo offset filename="d:\backup\dbname_%date:~0,10%"set zipfile="d:\backup\ ...

  10. [转][C#]ImageHelper

    { internal static class ImageHelper { public static Bitmap CloneBitmap(Image source) { if (source == ...