jar包发布到中央仓库详细教程

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


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


第一步:新建开源项目

第二步:新建账户

第三步:创建Issue

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

第五步:使用GPA生成秘钥

第六步:发布jar包

碰到的问题


第一步:新建开源项目

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


第二步:新建账户

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

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


第三步:创建Issue

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

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

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

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

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

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

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

  • 用域名邮箱发送email到[email protected]

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

这是我的域名解析截图


第四步:配置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>[email protected]</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

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 <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1



第六步:发布jar包

1. 发布 快照版本

mvn clean deploy


2. 发布正式版本

mvn clean deploy -P release


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

类似这样


碰到的问题

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


2. MAC下


Fixing GPG "Inappropriate ioctl for device" errors
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-gpg-plugin:1.5:sign (defaulton 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 (defaulton 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
[ERRORFor more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1http://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秘钥,重新生成

本文分享自微信公众号 - 阿提说说(itsaysay)。
如有侵权,请联系 [email protected] 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章