gradle使用maven-publish發(fā)布jar包上傳到私有maven配置
一、添加插件
apply plugin: 'maven-publish'
二、添加如下配置
//打包源碼 task sourceJar(type: Jar) { from sourceSets.main.allJava } publishing { publications { maven(MavenPublication) { //指定group/artifact/version信息,可以不填。默認(rèn)使用項(xiàng)目group/name/version作為groupId/artifactId/version groupId project.group artifactId project.name version project.version //如果是war包填寫(xiě)components.web,如果是jar包填寫(xiě)components.java from components.java //配置上傳源碼 artifact sourceJar { classifier "sources" } } } repositories { maven { //指定要上傳的maven私服倉(cāng)庫(kù) url = "http://jenkins.maxrocky.com:8080/maven/content/repositories/thirdparty/" //認(rèn)證用戶和密碼 credentials { username 'admin' password 'maxrocky5721' } } } }
三、執(zhí)行以下命令進(jìn)行上傳
gradle publishMavenPublicationToMavenRepository
正常的輸出結(jié)果
? gradle publishMavenPublicationToMavenRepository :common:generatePomFileForMavenPublication :common:compileJava UP-TO-DATE :common:processResources UP-TO-DATE :common:classes UP-TO-DATE :common:jar UP-TO-DAT :common:sourceJar UP-TO-DATE :common:publishMavenPublicationToMavenRepository Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jar Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jar.sha1 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jar.md5 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pom Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pom.sha1 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pom.md5 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jar Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jar.sha1 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jar.md5 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/maven-metadata.xml Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/maven-metadata.xml.sha1 Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/maven-metadata.xml.md5 BUILD SUCCESSFUL Total time: 1.906 secs
四、遇見(jiàn)的問(wèn)題
有時(shí)候會(huì)出錯(cuò),如下輸出
:common:generatePomFileForMavenPublication :common:compileJava UP-TO-DATE :common:processResources UP-TO-DATE :common:classes UP-TO-DATE :common:jar UP-TO-DATE :common:sourceJar UP-TO-DATE :common:publishMavenPublicationToMavenRepository Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.jar Could not transfer artifact com.kingboy:common:jar:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0.jar' Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0.pom Could not transfer artifact com.kingboy:common:pom:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0.pom' Upload http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/com/kingboy/common/1.0/common-1.0-sources.jar Could not transfer artifact com.kingboy:common:jar:sources:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0-sources.jar' :common:publishMavenPublicationToMavenRepository FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':common:publishMavenPublicationToMavenRepository'. > Failed to publish publication 'maven' to repository 'maven' > Failed to deploy artifacts: Could not transfer artifact com.kingboy:common:jar:1.0 from/to remote (http://jenkins.maven.com:8080/maven/content/repositories/thirdparty/): Could not write to resource 'com/kingboy/common/1.0/common-1.0.jar' * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED
我的是因?yàn)榫W(wǎng)絡(luò)原因,換個(gè)網(wǎng)絡(luò),多試幾次就成功了,去stackoverflow上看了以下,沒(méi)有太明確的原因。
以上就是gradle使用maven-publish發(fā)布jar包上傳到私有maven配置的詳細(xì)內(nèi)容,更多關(guān)于gradle發(fā)布jar包到私有maven的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
基于Java實(shí)現(xiàn)音樂(lè)播放器的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Java編寫(xiě)一個(gè)簡(jiǎn)單的音樂(lè)播放器,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解一下2023-07-07SpringBoot?+?Disruptor實(shí)現(xiàn)特快高并發(fā)處理及使用Disruptor高速實(shí)現(xiàn)隊(duì)列的過(guò)程
Disruptor是一個(gè)開(kāi)源的Java框架,它被設(shè)計(jì)用于在生產(chǎn)者—消費(fèi)者(producer-consumer problem,簡(jiǎn)稱PCP)問(wèn)題上獲得盡量高的吞吐量(TPS)和盡量低的延遲,這篇文章主要介紹了SpringBoot?+?Disruptor?實(shí)現(xiàn)特快高并發(fā)處理,使用Disruptor高速實(shí)現(xiàn)隊(duì)列,需要的朋友可以參考下2023-11-11java 轉(zhuǎn)發(fā)和重定向區(qū)別及實(shí)例代碼
這篇文章主要介紹了java 轉(zhuǎn)發(fā)和重定向區(qū)別及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-11-11Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(61)
下面小編就為大家?guī)?lái)一篇Java基礎(chǔ)的幾道練習(xí)題(分享)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望可以幫到你2021-08-08SpringBoot實(shí)現(xiàn)類似鉤子函數(shù)的方法
這篇文章主要給大家介紹了關(guān)于SpringBoot實(shí)現(xiàn)類似鉤子函數(shù)的方法,文中通過(guò)代碼示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-04-04在IntelliJ IDEA 搭建springmvc項(xiàng)目配置debug的教程詳解
這篇文章主要介紹了在IntelliJ IDEA 搭建springmvc項(xiàng)目配置debug的教程詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-09-09Spring?IOC中對(duì)象的創(chuàng)建、策略及銷毀時(shí)機(jī)和生命周期詳解
這篇文章主要介紹了Spring?IOC中對(duì)象的創(chuàng)建、策略及銷毀時(shí)機(jī)和生命周期詳解,Spring默認(rèn)使用類的空參構(gòu)造方法創(chuàng)建bean,假如類沒(méi)有空參構(gòu)造方法,將無(wú)法完成bean的創(chuàng)建,需要的朋友可以參考下2023-08-08