> 文章列表 > 自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

1.前言

如何把自己的项目Jar或者Starter上传到Maven中央仓库中。

2.https://issues.sonatype.org/注册账号

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

3.注册成功 登录新建项目

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
摘要随意填写
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

重点来了
groupId 如果有自己域名的就自己域名com.xxx
如果用的gitee那么填写com.gitee.自己gitee的用户名
projectUrl:仓库地址
scmurl:仓库https

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
填写完毕点击新建

4.看注释,验证个人仓库和修改错误信息

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

这里需要去刚刚配置的gitee上面新建公开仓库 新建一个名称他告诉你的仓库 验证是个人的账号
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
也根据错误信息 改正其他错误 比如我这个 开始填写的groupId不对

5. 新建个人仓库完毕之后回复审核管理员

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
等5-10分钟会来审核
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

值得注意的是 这个一步如果没通过你的账号是登录不上去https://s01.oss.sonatype.org/
下面这个错误 如果你没输错刚刚注册的账号密码  登录不上去 因为没审核通过 大坑=====

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

6.下载安装Gpg4Win

官网:https://www.gpg4win.org/下载慢
我自己的csdn下载地址:https://download.csdn.net/download/qq_42264638/87699270下载快

7.安装完成生成密匙

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

8.上传密钥

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

9.配置本地maven的settings文件

配置servers<servers><server><id>ossrh</id><username>第一步注册的账号issues.sonatype.org账号</username><password>第一步注册的密码issues.sonatype.org密码</password></server>
</servers>

配置profiles

<profiles>
<profile><id>ossrh</id><activation><activeByDefault>true</activeByDefault></activation><properties><gpg.executable>这里填你安装的GnuPG位置D:\\app\\GnuPG\\bin\\gpg.exe</gpg.executable><gpg.passphrase>刚才你生成密钥时输入的密码</gpg.passphrase><gpg.homedir>这里填你秘钥在磁盘上的位置C:\\Users\\xql15\\AppData\\Roaming\\gnupg</gpg.homedir></properties>
</profile>
</profiles>

10.配置上传项目的pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.gitee.xu_qing_lei</groupId><name>utils</name><artifactId>utils</artifactId><version>1.0</version><packaging>jar</packaging><description>init</description><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target></properties><!--开源协议--><licenses><license><name>Apache License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url><distribution>repo</distribution><comments>A business-friendly OSS license</comments></license></licenses><!--项目地址--><url>https://gitee.com/xu_qing_lei/utils</url><!--开发者信息--><developers><developer><id>utils</id><name>utils</name><email>2606482590@qq.com</email><roles><role>Developer</role></roles><timezone>+8</timezone></developer></developers><!--项目在github或其它托管平台的地址--><scm><connection>https://gitee.com/xu_qing_lei/utils.git</connection><developerConnection>scm:git:ssh://git@gitee.com:xu_qing_lei/utils.git</developerConnection><url>https://gitee.com/xu_qing_lei/utils/tree/master</url></scm><dependencies><!--mybatis启动器--><!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.1.0.RELEASE</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId><version>2.0.6.RELEASE</version></dependency><!--引入lombok相关jar--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.8</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><version>2.4</version><scope>provided</scope></dependency><!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore --><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpcore</artifactId><version>4.4.10</version></dependency><!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.6</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><scope>provided</scope><version>2.11.4</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.62</version></dependency><dependency><groupId>com.github.tobato</groupId><artifactId>fastdfs-client</artifactId><version>1.27.2</version><exclusions><exclusion><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>2.2.1</version><executions><execution><id>attach-sources</id><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><configuration><additionalJOptions><additionalJOption>-Xdoclint:none</additionalJOption></additionalJOptions></configuration><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.5</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin></plugins></build><distributionManagement><snapshotRepository><id>ossrh</id><url>https://s01.oss.sonatype.org/content/repositories/snapshots</url></snapshotRepository><repository><id>ossrh</id><url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement></project>

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
这个地方填写自己的项目信息
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
项目地址和开发者信息 修改成自己的信息
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
项目的scm地址修改成自己的仓库地址

<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>2.2.1</version><executions><execution><id>attach-sources</id><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>2.9.1</version><configuration><additionalJOptions><additionalJOption>-Xdoclint:none</additionalJOption></additionalJOptions></configuration><executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.5</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin></plugins></build>

build直接copy即可
也可以自己参考官网配置
https://maven.apache.org/guides/mini/guide-configuring-plugins.html

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

10.打包 上传deploy

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

mvn clean compile package deploy

执行完成会弹窗 输入第一次生成密匙的密码
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
查看控制台出现BUILD SUCCESS
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

11.登录https://s01.oss.sonatype.org

登录入口:https://s01.oss.sonatype.org自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

账号密码同第一步注册的issues.sonatype.org
在这里插入图片描述

第一步点击左侧的:Staging Repositories
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

第二步:勾选
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
第三步点击Close

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库

第四步填写弹窗信息随意填写
第五步可以查看是否成功报错信息点击
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
如果没有报错信息更好 有则根据报错信息 修改pom文件
Drop当前文件 重新上传即可 deploy
第六步:发现如果无报错Release会可以点击
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
点击确定Confirm

12.我们去仓库搜一下我们上传的jar有可能有延迟

自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库
https://developer.aliyun.com/mvn/search
也可以在阿里云效搜索
自定义jar项目上传到Maven中央仓库/maven仓库/阿里云效仓库