Gradle5.x打jar包上传maven仓库

1.上传本地仓库

1.1 build.gradle 项目设置

plugins {
    id 'java'
    id 'maven' //引入maven插件
}

group 'com.inkyi' //包名
version '1.0.1-SNAPSHOT' //版本号

1.2 build.gradle 上传设置

// 指定上传的路径
def localMavenRepo = 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath

// 上传Task,Gradle会生成并上传pom.xml文件。
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: localMavenRepo)//构造项目的Pom文件
            pom.project {
                name = project.name
                packaging = 'jar'
                description = 'description'
            }
        }

    }
}

1.3 项目根目录执行命令

Z:\xxxxxx>gradle uploadArchives

BUILD SUCCESSFUL in 0s
3 actionable tasks: 1 executed, 2 up-to-date

2.上传私有仓库(参考Gradle Plugin文档,没有真正上传过)

2.1 build.gradle 项目设置和上面的 1.1 一样

2.2 build.gradle 上传设置

// 上传Task,Gradle会生成并上传pom.xml文件。
uploadArchives {
repositories {
mavenDeployer {
       //这个地方,多了填写用户名和密码的方法,用来私有仓库的验证
repository(url: "scp://repos.mycompany.com/releases") {
authentication(userName: "me", password: "myPassword")
}
//构造项目的Pom文件
pom.project {
name = project.name
packaging = 'jar'
description = 'description'
}
}

}
}

2.3 项目根目录执行命令与1.3是一样的

上传本地仓库的我试过是可以用的,上传私有仓库的还没试过,建议有不符合的地方,参考文档再调整一下。文档地址:https://docs.gradle.org/current/userguide/maven_plugin.html

猜你喜欢

转载自www.cnblogs.com/inkyi/p/10469740.html