在Jenkins中構建項目,遇到maven缺乏插件的問題:spring
[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
方法一:apache
有時maven庫中的插件很差拉取,如網速很差或特殊的項目依賴包等因素,能夠將須要的jar包直接添加到本地maven庫中,減小不少麻煩。json
一、準備好須要的jar包,放置在方便的路徑下,並進入到這個目錄vim
二、執行命令:mvn install:install-file -Dfile=json-simple-1.1.1.jar -DgroupId=org.json -DartifactId=json-simple -Dversion=1.1.1 -Dpackaging=jar服務器
須要什麼包就改爲相應的名字,執行後將出現下面提示,以後構建就不會出現maven缺包的狀況:maven
方法二:spring-boot
,我今天遇到這個狀況,方法一不起效,在本機上直接執行構建命令就能夠構建成功,可是在Jenkins上構建,仍是報上面的錯誤,檢查了Jenkins的配置 ,項目配置,沒有發現任何問題,無奈之下,只有設置Jenkins的全局變量設置,將maven改爲自動安裝:系統管理-->全局工具配置-->maven工具
而後打開項目配置,在pre step中添加mvn的添加插件到倉庫的命令,須要注意的是,要在服務器的相應目錄中準備好jar包,配置保存後,構建項目就不會出現maven缺乏包的問題了。ui
(我構建以前是將服務器上的maven卸載了的,Jenkins在構建項目時,會下載maven這個插件,而後在Jenkins的目錄下保存maven的倉庫,那卸不卸載本機的maven,看你本身的了)url
設置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>
如圖:
以後從新編譯項目就行了