maven 手动添加jar包到本地仓库,及处理报错Failed to transfer file: http://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.0.RELEASE/spring-boot-starter-parent-2.1.0.RELEASE.pom.

在Jenkins中构建项目,遇到maven缺少插件的问题:

[ERROR] Failed to execute goal on project mianshi-service: Could not resolve dependencies for project com.shiku:mianshi-service:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.xiaomi.push:mipush-sdk-server:jar:2.2.18, org.json:json-simple:jar:1.1.1: Could not find artifact com.xiaomi.push:mipush-sdk-server:jar:2.2.18 in spring-snapshots (http://repo.spring.io/snapshot) -> [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
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :mianshi-servi

方法一:

有时maven库中的插件不好拉取,如网速不好或特殊的项目依赖包等因素,可以将需要的jar包直接添加到本地maven库中,减少很多麻烦。

1、准备好需要的jar包,放置在方便的路径下,并进入到这个目录

2、执行命令:mvn install:install-file   -Dfile=json-simple-1.1.1.jar  -DgroupId=org.json  -DartifactId=json-simple -Dversion=1.1.1  -Dpackaging=jar

需要什么包就改成相应的名字,执行后将出现下面提示,之后构建就不会出现maven缺包的情况:

 

方法二:

,我今天遇到这个情况,方法一不起效,在本机上直接执行构建命令就可以构建成功,但是在Jenkins上构建,还是报上面的错误,检查了Jenkins的配置 ,项目配置,没有发现任何问题,无奈之下,只有设置Jenkins的全局变量设置,将maven改成自动安装:系统管理-->全局工具配置-->maven

然后打开项目配置,在pre step中添加mvn的添加插件到仓库的命令,需要注意的是,要在服务器的相应目录中准备好jar包,配置保存后,构建项目就不会出现maven缺少包的问题了。

(我构建之前是将服务器上的maven卸载了的,Jenkins在构建项目时,会下载maven这个插件,然后在Jenkins的目录下保存maven的仓库,那卸不卸载本机的maven,看你自己的了)

 

设置maven仓库地址

最近遇到一个问题,在编译程序时,在 Parsing POMs时报错,错误如下:

ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Failure to transfer org.springframework.boot:spring-boot-starter-parent:pom:2.1.0.RELEASE from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:2.1.0.RELEASE from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/2.1.0.RELEASE/spring-boot-starter-parent-2.1.0.RELEASE.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. and 'parent.relativePath' points at wrong local POM @ line 12, column 13

这个错误提示我们,在 http://repo.maven.apache.org/maven2中找不到我们要的资源,我翻了所有关于maven的配置文件,没发现仓库配有这个地址,那算了,重新配置一个镜像

编辑maven的配置文件settings.xml,具体位置在哪,根据安装路径找一下  find / -name settings.xml

vim settings.xml

在mirrors中添加一下配置

<mirror>
 <id>alimaven</id>
 <name>aliyun maven</name>
 <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
 <mirrorOf>central</mirrorOf>
</mirror>

如图:

 

 

 

之后重新编译项目就好了

posted @ 2019-03-08 17:52  christine-ting  阅读(4712)  评论(0编辑  收藏  举报