在改造一個舊項目中,遇到各種問題。
舊項目有十多個模塊,因為沒有一個統一的父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 之后就好了!