gradle怎么使用maven-publish发布jar包上传到私有maven

这篇文章主要介绍“gradle怎么使用maven-publish发布jar包上传到私有maven”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“gradle怎么使用maven-publish发布jar包上传到私有maven”文章能帮助大家解决问题。

一、添加插件

apply plugin: 'maven-publish'

二、添加如下配置

//打包源码
task sourceJar(type: Jar) {
    from sourceSets.main.allJava
}
publishing {
    publications {
        maven(MavenPublication) {
            //指定group/artifact/version信息,可以不填。默认使用项目group/name/version作为groupId/artifactId/version
            groupId project.group
            artifactId project.name
            version project.version
            //如果是war包填写components.web,如果是jar包填写components.java
            from components.java
            //配置上传源码
            artifact sourceJar {
                classifier "sources"
            }
        }
    }
    repositories {
        maven {
            //指定要上传的maven私服仓库
            url = "http://jenkins.maxrocky.com:8080/maven/content/repositories/thirdparty/"
            //认证用户和密码
            credentials {
                username 'admin'
                password 'maxrocky5721'
            }
        }
    }
}

三、执行以下命令进行上传

gradle publishMavenPublicationToMavenRepository

正常的输出结果

➜ 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

四、遇见的问题

有时候会出错,如下输出

: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

我的是因为网络原因,换个网络,多试几次就成功了,去stackoverflow上看了以下,没有太明确的原因。

关于“gradle怎么使用maven-publish发布jar包上传到私有maven”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注蜗牛博客行业资讯频道,小编每天都会为大家更新不同的知识点。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论Telegram