maven dependency的版本衝突問題

在改造一箇舊項目中,遇到各類問題。java

舊項目有十多個模塊,由於沒有一個統一的父pom,它們對第三方的jar的版本沒有統一。 雖然也存在公共的依賴模塊,好比commons、util,可是,咱們的模塊中,有時候又會本身重複引用一些基礎的、已經在公共依賴模塊存在的對三方jar, 這樣 就形成了不少的衝突。web

當我考慮統一到一個父pom裏面去的時候,發現了不少問題。redis

 

 1 spring

[ERROR] apache

[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]api

3.6.10.Final.是什麼東東,發現是 子模塊中寫死的一個 property, 雖然沒有在 dependency中使用它,可是它卻生效了,真是神奇了。 大概是它把 spring-boot 的同名的 property 覆蓋了吧, 可是 spring-boot 的當前版本依賴的netty 並非 3.6.10.Final., 因此就出現了這個問題。 tomcat

怎麼解決: 把3.6.10.Final. 的property 刪除掉就行了。不過呢,「SNAPSHOT does not allow version」 是啥?    搞不懂app

 

[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/DependencyResolutionExceptiondom

同上的緣由。maven

 

 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 以後就行了!

相關文章
相關標籤/搜索