jar包上传到maven中央仓库

jar包上传到maven中央仓库

1、背景
最近有好几个项目并行开发,几个项目都有类似得功能,如:音视频分离、音视频转码、doc/excel/ppt/img等文件转pdf,pdf转图片等功能,,为了防止开发人员重复造轮子,封装了一个sdk,供团队使用,

sdk源码讲解下个章节,可以留言提需求

2、封装好得sdk如何给团队使用

  • 上传到公司得私服(流程一大堆—舍弃)
  • sdk放入项目中(sdk更新,替换繁杂)
  • 上传到maven中央仓库,自行下载与升级(个人比较喜欢)

3、上传步骤

  • 注册sonatype账号:【申请上传资格】
https://issues.sonatype.org/secure/Signup!default.jspa

在这里插入图片描述

  • 登录
    在这里插入图片描述
  • 新建issue
https://issues.sonatype.org/secure/CreateIssue.jspa?issuetype=21&pid=10134

在这里插入图片描述
等下面红框变成已解决,表示审核成功
在这里插入图片描述

  • 构件仓库上传jar包

1、本地安装gpg,并使用gpg生成密钥对

注:发布到Maven仓库中的所有文件都要使用GPG签名,以保障完整性。

2、下载安装gpg4win

https://www.gpg4win.org/download.html

默认安装就行

3、使用gpg生成密钥对

gpg --gen-key

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
记住key值,后面用到

4、上传GPG公钥

gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 0904BE8DA21578C2
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 0904BE8DA21578C2

查询公钥是否发布成功

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 0904BE8DA21578C2
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 0904BE8DA21578C2

在这里插入图片描述
5、在maven的setting.xml配置文件中添加如下节点信息:

  <servers>
	  <server>
	      <id>ossrh</id>
	      <username>Sonatype账号</username>
	      <password>Sonatype密码</password>
	  </server>
	  <!-- 上传jar包到maven中央仓库配置end -->
  </servers>
    <profiles>
		<profile>
			<id>ossrh</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			
			<properties>
				<gpg.executable>D:\java\GPG\GnuPG\bin\gpg(根据实际安装路径修改)</gpg.executable>
				<gpg.passphrase>刚才生成得key</gpg.passphrase>
			</properties>
		</profile>
	<profiles>

6、配置项目的pom.xml文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.5</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.gitee.renhaisong</groupId>
    <artifactId>hsren-util-sdk</artifactId>
    <version>1.0</version>
    <name>sdk</name>
    <description>hsren 工具类</description>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
    <!-- 开发者信息 -->
    <developers>
        <developer>
            <name>renhaisong</name>
            <email>577356779@qq.com</email>
            <url>https://gitee.com/hsr</url>
        </developer>
    </developers>
    <!-- SCM信息 -> git在github上托管 -->
    <scm>
        <connection>https://gitee.com/hsr/sdk.git</connection>
        <developerConnection>https://gitee.com/hsr</developerConnection>
        <url>https://gitee.com/hsr/sdk</url>
    </scm>
    <!-- 【注】snapshotRepository 与 repository 中的 id 一定要与 setting.xml 中 server 的 id 保持一致! -->
    <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>
    <dependencies>

    </dependencies>
    <build>
        <plugins>
            <!-- 源码 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Javadoc -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <additionalparam>-Xdoclint:none</additionalparam>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--部署-->
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <executions>
                    <execution>
                        <id>deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- GPG 打包插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--将组件部署到OSSRH并将其发布到Central Repository-->
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.8</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

7、部署和发布Jar包

 mvn clean deploy -DskipTests

在这里插入图片描述
8、访问 https://s01.oss.sonatype.org/

在这里插入图片描述
经过几个小时,就可以在 maven仓库 中找到

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值