最新版Jar包发布到中央仓库详细教程

之前将一个经过修改的shiro tag jar包发布到了中央仓库,过程曲折,因为网上的教程大都已经过期。今天为了写这篇文章,又把过程走了一遍,现将最新发布过程记录下来

#进行如下操作,建议打开fanqiang软件

6ec048a3c2dcf1164d5a62c3bb18de6bafa.jpg

第一步:新建开源项目

第二步:新建账户

第三步:创建Issue

第四步:配置pom.xml 和 settings.xml

第五步:使用GPA生成秘钥

第六步:发布jar包

碰到的问题

第一步:新建开源项目

在仓库中新建你的开源项目

第二步:新建账户

新建一个Sonatype的账户,注册地址,记住自己的账户密码,后面会用到

https://issues.sonatype.org/secure/Signup!default.jspa

第三步:创建Issue

创建Issue,登录后点击头部Create按钮

96539b3327136ee49ff36e59fed178ddb30.jpg

新弹出窗口,填下面几项信息

9830e2385617732588ee220285a176b6451.jpg

创建完后,在这里查看提交的Issues

c80148c9a7bf0a3436c7b8a562ce40dee55.jpg

提交完不久,你会收到一个回复,询问是否有权限管理域名

回复yes or no,yes的话按提供的三种方法进行验证

  • 在域名解析中添加一条TXT解析到该Issues的地址

  • 域名解析中添加一个跳转到你的github项目页面地址

  • 用域名邮箱发送email到central@sonatype.com

如果no,你就得用github的域名了

7e027d3a68d8fc0b442ca2a418aa9e6f076.jpg

这是我的域名解析截图

b53989fa327fdbdf88fe0b634c3ad47a738.jpg

 

第四步:配置pom.xml 和 settings.xml

a.上面的工作都昨完了,我们就要配置项目的pom.xml了

这是我的pom.xml文件,你可以按照上面的进行配置

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->
<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.zhiplusyun</groupId>
    <artifactId>common-base</artifactId>
    <version>1.0.1</version>

    <name>zhiplusyun common-base</name>
    <description>zhiplusyun sass common-base</description>
    <url>https://www.zhiplusyun.com/</url>

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


    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>https://github.com/zhiplusyun/sass-common/blob/master/LICENSE</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>jujunchen</name>
            <email>1913210361@qq.com</email>
            <url>http://www.178le.net</url>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:https://github.com/zhiplusyun/sass-common.git</connection>
        <developerConnection>scm:git:https://github.com/zhiplusyun/sass-common.git</developerConnection>
        <url>https://github.com/zhiplusyun/sass-common.git</url>
    </scm>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
    </properties>


    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>compile</scope>
            <version>1.16.20</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>2.3</version>
        </dependency>

    </dependencies>


    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <!-- Source -->
                    <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>3.0.1</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- GPG -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.5</version>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <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://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.3</version>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

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

        </profile>
    </profiles>


</project>

b.在Maven settings.xml 的 servers 节点配置如下信息

<server>
      <id>sonatype-nexus-snapshots</id>
      <username>第二步注册的sonatype账号</username>
      <password>sonatype密码</password>
    </server>
    <server>
      <id>sonatype-nexus-staging</id>
      <username>sonatype账号</username>
      <password>sonatype密码</password>
</server>

 

第五步:使用GPA生成秘钥

win版下载地址:https://gpg4win.org/

mac,linux 直接用 命令安装,我相信你知道该怎么装的

这有几个命令

1. 查看是否安装成功, 显示版本号等信息表明安装成功

gpg --version

2. 生成秘钥 ,提示让你输入 姓名,邮箱,还有一个密码,完了后生成秘钥,如图

gpg --gen-key

606ef6e9f7593cf0f73a12d4a39d0a1f854.jpg

FD6B7B6531EDB4567F2870B5978A660E8D315F31 这个就是公钥

3. 上传公钥到服务器

gpg --keyserver hkp://pool.sks-keyservers.net --send-keys FD6B7B6531EDB4567F2870B5978A660E8D315F31

如果发送失败会显示,我这里因为是网络原因,多尝试几次

gpg: sending key 978A660E8D315F31 to hkp://pool.sks-keyservers.net
gpg: keyserver send failed: No data
gpg: keyserver send failed: No data

4. 查看是否发送成功

gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys FD6B7B6531EDB4567F2870B5978A660E8D315F31
gpg: key 978A660E8D315F31: "zhiplusyun <1913210361@qq.com>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

第六步:发布jar包

1. 发布 快照版本

mvn clean deploy

2. 发布正式版本

mvn clean deploy -P release

正式发布后,去Issue回复,过1-2天查看回复

953bf59f30cfab1885ec431b44e7d1b984a.jpg

类似这样

3c77fb38c9092ed0eaf9f31fa90ca78db1f.jpg

 

碰到的问题

1. 快照版本能正常发布,发布正式版的时候,碰到 Access denied 或者 403问题 ,这要在Issue上回复一下,工作人员会给你的账号进行权限修复

40c435d026da929b67130474ab3964df8db.jpg

f0161c136c9bfc561641bce9d4589b8442f.jpg

2. MAC下

Fixing GPG "Inappropriate ioctl for device" errors
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (default) on project shiro-freemarker-tags: Exit code: 127 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (default) on project shiro-freemarker-tags: Exit code: 127
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Exit code: 127
        at org.apache.maven.plugin.gpg.GpgSigner.generateSignatureForFile(GpgSigner.java:168)
        at org.apache.maven.plugin.gpg.AbstractGpgSigner.generateSignatureForArtifact(AbstractGpgSigner.java:205)
        at org.apache.maven.plugin.gpg.GpgSignAttachedMojo.execute(GpgSignAttachedMojo.java:140)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 20 more
[ERROR] 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

解决方法:

To solve the problem, you need to enable loopback pinentry mode. Add this to~/.gnupg/gpg.conf:

use-agent
pinentry-mode loopback

And add this to ~/.gnupg/gpg-agent.conf, creating the file if it doesn't already exist:

allow-loopback-pinentry

3.  Rule failure while trying to close staging repository with ID

发生的场景,第一次jar包为 快照版本,但我用了mvn clean deploy -P release 发布,在修改为正式版本后,再执行命令就报错了

解决方法:删除原来的GPA秘钥,重新生成

68cc1d362dcafb612b62be454426bcdbf2d.jpg

转载于:https://my.oschina.net/itsaysay/blog/3011822

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值