mvn 构建错误总结
问题总结:
mvn仓库查找顺序
本地仓库=>没有就找中央仓库=>远程仓库
mvn 构建失败三大原因
1.误删除 ./m2文件夹,构建失败
- 解决:重新使用中央仓库拉取配置
2.本地仓库是否有错误依赖(以lastUpdated结尾)缓存失败;
产生的原因:可能是网络波动或者前期新手配置有误
解决方案: 删除本地有问题的依赖
命令:find * -type f -name "*.lastUpdated"|xargs rm -f
3.本地缓存删除完,再重新打包,还是报错、
思路:查看配置settings配置
[root@localhost g7lite-dos]# cat /data/home/soft/maven/conf/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>huawei-maven</id>
<url>https://repo.huaweicloud.com/repository/maven/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
比如说华为的使用的是*,后面还需要跟!HuaweiCloudSDK
<mirror>
<id>huaweicloud</id>
<mirrorOf>*,!HuaweiCloudSDK</mirrorOf>
<url>https://repo.huaweicloud.com/repository/maven/</url>
</mirror>
4.最后有些依赖需要的是私服包,如果有报错可能存在原因是401密码失败
私服包记得配置用户名和密码
<servers>
<server>
<id>rdc-releases</id>
<username>6406ded884946b4453bf</username>
<password>gIqj1xuO8-</password>
</server>
<server>
<id>rdc-snapshots</id>
<username>6406de2454d96b4453bf</username>
<password>gIqj1xuOy-</password>
</server>
</servers>
5.第五点,如果有特殊的依赖包,比如说华为的
参考:https://mirrors.huaweicloud.com/home
<profile>
<id>MyProfile</id>
<repositories>
<repository>
<id>HuaweiCloudSDK</id>
<url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>HuaweiCloudSDK</id>
<url>https://repo.huaweicloud.com/repository/maven/huaweicloudsdk/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
需要在最下方配置
增加activeProfiles标签激活配置:
<activeProfiles>
<activeProfile>MyProfile</activeProfile>
</activeProfiles>
=============================================================================
以下是细节排错
记一次mvn构建打包失败
我将 ./m2的文件全给删除了,此时配置的mvn命令无法打包,各种报错。
报错如下
mvn clean install -Dmaven.test.skip=true
[INFO] Scanning for projects...
[ERROR][ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'dependencies.dependency.systemPath' for com.chinawayltd.java.spec:globally-unique-id-generator:jar should not point at files within the project directory, ${basedir}/lib/globally-unique-id-generator-1.0.0-SNAPSHOT.jar will be unresolvable by dependent projects @ line 183, column 25
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 315, column 21
[WARNING] The expression ${name} is deprecated. Please use ${project.name} instead. @
[WARNING] The expression ${name} is deprecated. Please use ${project.name} instead. @
[ERROR] Non-resolvable import POM: Could not find artifact com.chinawayltd.g7lite:g7lite-dependencies:pom:1.0.0-SNAPSHOT @ line 368, column 25
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-web:jar is missing. @ line 38, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-test:jar is missing. @ line 52, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-configuration-processor:jar is missing. @ line 57, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-expression:jar is missing. @ line 62, column 21
[ERROR] 'dependencies.dependency.version' for org.apache.commons:commons-lang3:jar is missing. @ line 66, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar is missing. @ line 70, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-openfeign:jar is missing. @ line 80, column 21
[ERROR] 'dependencies.dependency.version' for com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar is missing. @ line 84, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-actuator:jar is missing. @ line 88, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-data-redis:jar is missing. @ line 102, column 21
[ERROR] 'dependencies.dependency.version' for org.projectlombok:lombok:jar is missing. @ line 106, column 21
[ERROR] 'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 134, column 21
[ERROR] 'dependencies.dependency.version' for com.alibaba:fastjson:jar is missing. @ line 165, column 21
[ERROR] 'dependencies.dependency.version' for com.ctrip.framework.apollo:apollo-client:jar is missing. @ line 171, column 21
@
[ERROR] The build could not read 1 project -> [Help 1][ERROR]
[ERROR] The project com.chinawayltd.g7lite:ins-saas-uc:1.0.0 (/root/thb/g7-saas-uc/pom.xml) has 15 errors
[ERROR] Non-resolvable import POM: Could not find artifact com.chinawayltd.g7lite:g7lite-dependencies:pom:1.0.0-SNAPSHOT @ line 368, column 25 -> [Help 2][ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-web:jar is missing. @ line 38, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-test:jar is missing. @ line 52, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-configuration-processor:jar is missing. @ line 57, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework:spring-expression:jar is missing. @ line 62, column 21
[ERROR] 'dependencies.dependency.version' for org.apache.commons:commons-lang3:jar is missing. @ line 66, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar is missing. @ line 70, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.cloud:spring-cloud-starter-openfeign:jar is missing. @ line 80, column 21
[ERROR] 'dependencies.dependency.version' for com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar is missing. @ line 84, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-actuator:jar is missing. @ line 88, column 21
[ERROR] 'dependencies.dependency.version' for org.springframework.boot:spring-boot-starter-data-redis:jar is missing. @ line 102, column 21
[ERROR] 'dependencies.dependency.version' for org.projectlombok:lombok:jar is missing. @ line 106, column 21
[ERROR] 'dependencies.dependency.version' for mysql:mysql-connector-java:jar is missing. @ line 134, column 21
[ERROR] 'dependencies.dependency.version' for com.alibaba:fastjson:jar is missing. @ line 165, column 21
[ERROR] 'dependencies.dependency.version' for com.ctrip.framework.apollo:apollo-client:jar is missing. @ line 171, column 21
[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/ProjectBuildingException
[ERROR][Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
#参考解决方案:
https://blog.csdn.net/cushier/article/details/82223656
总结:意思就是把 .m2整个仓库删掉,配置mvn的中央仓库再拉取一遍
仓库依赖不存在
此时我可以进行构建了,但是我构建的项目是华为的大数据,此时又出现了本地仓库依赖不存在的问题,于是我又新增了华为的mvn仓库源
我在settings配置了很多多个源
报错如下
实际上,把mvn官方的中央仓库给删掉,此时就可以重新加载了。
问题3
但是,我发现用了华为源后,有些可以download,但是我需要的那些依赖包又没找到,报错。
报错如下
mvn clean install -Dmaven.test.skip=true -X 详细排查了下
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: The following artifacts could not be resolved: org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:7.6.0-hw-ei-302002, org.elasticsearch:elasticsearch:jar:7.6.0-hw-ei-302002, org.elasticsearch.client:elasticsearch-rest-client:jar:7.6.0-hw-ei-302002, org.apache.hadoop:hadoop-common:jar:3.1.1-hw-ei-302002, org.apache.hbase:hbase-common:jar:2.2.3-hw-ei-302002, org.apache.hbase:hbase-client:jar:2.2.3-hw-ei-302002: Failure to find org.elasticsearch.client:elasticsearch-rest-high-level-client:jar:7.6.0-hw-ei-302002 in https://mirrors.huaweicloud.com/repository/maven/ was cached in the local repository, resolution will not be reattempted until the update interval of huawei-maven has elapsed or updates are forced
说好像被缓存了,于是我去本地仓库去找,发现了本地缓存的文件
[root@localhost 7.6.0-hw-ei-302002]# ll
total 8
-rw-r--r-- 1 root root 374 Apr 26 10:47 elasticsearch-rest-client-7.6.0-hw-ei-302002.jar.lastUpdated
-rw-r--r-- 1 root root 374 Apr 26 10:46 elasticsearch-rest-client-7.6.0-hw-ei-302002.pom.lastUpdated
这种结尾的
参考博客: https://blog.csdn.net/MXDMAX/article/details/123513034
原因可能是因为网络波动,或者找不到包但是下载了上述的文件 删掉,重新跑一遍就可以了。
find * -type f -name "*.lastUpdated" |xargs rm -f
[root@localhost repository]# find * -type f -name "*.lastUpdated"
com/chinawayltd/g7lite/g7lite-common/1.0.0-SNAPSHOT/g7lite-common-1.0.0-20221118.064604-1.pom.lastUpdated
org/apache/hadoop/hadoop-common/3.1.1-hw-ei-302002/hadoop-common-3.1.1-hw-ei-302002.pom.lastUpdated
org/apache/hadoop/hadoop-common/3.1.1-hw-ei-302002/hadoop-common-3.1.1-hw-ei-302002.jar.lastUpdated
org/apache/hbase/hbase-common/2.2.3-hw-ei-302002/hbase-common-2.2.3-hw-ei-302002.pom.lastUpdated
org/apache/hbase/hbase-common/2.2.3-hw-ei-302002/hbase-common-2.2.3-hw-ei-302002.jar.lastUpdated
org/apache/hbase/hbase-client/2.2.3-hw-ei-302002/hbase-client-2.2.3-hw-ei-302002.pom.lastUpdated
org/apache/hbase/hbase-client/2.2.3-hw-ei-302002/hbase-client-2.2.3-hw-ei-302002.jar.lastUpdated
org/elasticsearch/client/elasticsearch-rest-client/7.6.0-hw-ei-302002/elasticsearch-rest-client-7.6.0-hw-ei-302002.pom.lastUpdated
org/elasticsearch/client/elasticsearch-rest-client/7.6.0-hw-ei-302002/elasticsearch-rest-client-7.6.0-hw-ei-302002.jar.lastUpdated
org/elasticsearch/client/elasticsearch-rest-high-level-client/7.6.0-hw-ei-302002/elasticsearch-rest-high-level-client-7.6.0-hw-ei-302002.pom.lastUpdated
org/elasticsearch/client/elasticsearch-rest-high-level-client/7.6.0-hw-ei-302002/elasticsearch-rest-high-level-client-7.6.0-hw-ei-302002.jar.lastUpdated
org/elasticsearch/elasticsearch/7.6.0-hw-ei-302002/elasticsearch-7.6.0-hw-ei-302002.pom.lastUpdated
org/elasticsearch/elasticsearch/7.6.0-hw-ei-302002/elasticsearch-7.6.0-hw-ei-302002.jar.lastUpdated
[root@localhost repository]# find * -type f -name "*.lastUpdated" |xargs rm -f
[root@localhost repository]# find * -type f -name "*.lastUpdated"
[root@localhost repository]# cd