上传jar包到maven官方仓库

参考:

OSSRH Guide - The Central Repository Documentation

如何把自己的Jar包上传到 maven 官方仓库中,Maven上传图文讲解 —技术博客

写一遍我自己成功上传的整个流程,遇到的错误,记录下来。

一、创建工单

   1.注册账号 What Happened To issues.sonatype.org? - The Central Repository Documentation

      

     Username和Password要记住,这是部署到官方仓库的凭证,在maven的settings.xml中配置,后面会讲到。

   2.创建工单

      在这里遇到一个问题,当我点击create的时候,弹出来的窗口和上面我参考的那个人写的不一样,是这样的

      

      没有出现Group Id 、Project URL、SCM url这三个必填项,当再次选择最上面的 Project 

      再次选择Community Support - Open Source Project Repository Hosting (OSSRH) 就出现了

      

      按照要求填写就可以了,我有域名group id 填的 com.dcssn ,project url 填写 https://github.com/weiangongsi/ueditor-qiniu-        spring-boot-starter 项目地址, scm url 填写 https://github.com/weiangongsi/ueditor-qiniu-spring-boot-starter.git git地址。这        里主要验证的是group id 唯一性,然后点击create

      What Happened To issues.sonatype.org? - The Central Repository Documentation 打开这个页面找到自己提交的工单

      

      7分钟后他回复了一条信息,让我验证dcssn.com归我所有,第一种方式在dns解析中添加一个txt记录

      记录值就是工单,我填写的是这个工单的url  What Happened To issues.sonatype.org? - The Central Repository Documentation

      点击下面红色圈住的地方,跳转的就是工单地址

      

      dns添加解析后,回复一下,等了5分钟后回复我了

      

      这样就能发布jar包了,当发布成功后再告诉他已经发布了,就可以了。

二、上传jar包

   1.maven settings.xml配置修改

  <servers>
	<server> 
        <id>sonatype-nexus-snapshots</id> 
        <username>上面申请的用户名</username> 
        <password>上面申请的密码</password> 
    </server>
	<server> 
        <id>sonatype-nexus-staging</id> 
        <username>上面申请的用户名</username> 
        <password>上面申请的密码</password> 
    </server>
  </servers>

   2.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.dcssn</groupId>
    <artifactId>ueditor-qiniu-spring-boot-starter</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>

    <name>ueditor-qiniu-spring-boot-starter</name>
    <description>百度编辑器向七牛云存储上传图片资源</description>
    <url>https://github.com/weiangongsi/</url>

    <parent>
        <groupId>org.sonatype.oss</groupId>
        <artifactId>oss-parent</artifactId>
        <version>8</version>
    </parent>

    <dependencies>


    </dependencies>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/weiangongsi/ueditor-qiniu-spring-boot-starter</url>
        <connection>https://github.com/weiangongsi/ueditor-qiniu-spring-boot-starter.git</connection>
        <developerConnection>https://github.com/weiangongsi/</developerConnection>
    </scm>

    <developers>
        <developer>
            <name>lihaoyang</name>
            <email>weiangongsi@gmail.com</email>
            <url>https://www.dcssn.com</url>
        </developer>
    </developers>


    <distributionManagement>
        <repository>
            <id>sonatype-nexus-staging</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <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>
                <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>

</project>

      这些配置都是必须的,参照着改。

      有gpg 签名这个东西,有点麻烦,第一天弄了半天也不行,第二天早上来上班,不知道怎么就行了,可能就是软件安装后要        重启吗?

      Gpg4win - Secure email and file encryption with GnuPG for Windows 下载安装

      

      双击打开,点击文件-》新建密钥对,选择创建个人OpenPGP密钥对

      

        

     高级设置里面可以设置过期时间什么的,我没有设置,直接下一步

      

     会有一个提示输入密码的窗口,这个密码不要忘记,maven setting.xml 会用到,maven deploy命令部署上传的时候会用到

      创建成功后会在列表中显示,右键 在服务器上发布,成功后会提示导出成功

      

      maven seetting.xml 加入gpg配置

  <profiles>
	 <profile>
      <id>sign-artifacts</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <gpg.executable>gpg</gpg.executable>
        <gpg.passphrase>上面创建密钥的密码</gpg.passphrase>
      </properties>
    </profile>
  </profiles>

      

三、发布

   登录Nexus Repository Manager 账号密码就是创建工单时申请的账号密码

   

选中后点击close ,close成功后点击Release 就发布了

在左边的search框中输入就能搜到了

第一次成功后要在那个工单下面回复一下,

deploy时遇到了 400 和 401 错误

401 是因为maven setting.xml中 用户名或密码填错了

  <servers>
	<server> 
        <id>sonatype-nexus-snapshots</id> 
        <username>***</username> 
        <password>***</password> 
    </server>
	<server> 
        <id>sonatype-nexus-staging</id> 
        <username>***</username> 
        <password>***</password> 
    </server>
  </servers>

400 是因为 快照仓库和正式仓库地址填反了

<distributionManagement>
        <repository>
            <id>sonatype-nexus-staging</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

发布快照版本

pom.xml 中的 版本加上-SNAPSHOT

<version>0.0.1-SNAPSHOT</version>

发布正式版本 不加-SNAPSHOT就行了

<version>0.0.1</version>

使用快照版本的 在项目pom.xml中加入  每次构建项目都会从远程获取最新的快照版本

    <repositories>
        <repository>
            <id>sonatype-nexus-snapshots</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

Q群:806893930 

防火布

             

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值