关于java:上传jar到maven中央仓库

目前有很多相似教程,但都曾经过期了,当初Maven地方仓库的上传规定有新的变动,老的形式曾经不实用了。本人的开源jar在上线Maven地方仓库的过程中,卡壳屡次,通过不懈努力,总算是胜利上架了。特意记录一下过程(2022-06-30)。

1. 创立工单

创立工单的前提是先得有本人的账号,地址:https://issues.sonatype.org/
明码规定要求比拟高。务必要记住此明码,前面操作要屡次用到账号和明码。
申请操作如下:

2. 确认group id

提交后,接下来就急躁期待工作人员审核,有时候很快几分钟就会回复,有时候很慢,存在时差,刷新评论里看到要你确认的货色,注册账号时填写的邮箱也会收到告诉。
如下图这样,按要求实现其一即可,而后在评论里回复他说你做好了即可,而后期待告诉。

3. gpg 装置

gpg的作用是生成密钥对,会用于后续咱们组件公布的校验。
下载地址: https://www.gnupg.org/download/,在装置实现后,须要创立密钥对,UI和命令的模式二者选一即可。
UI模式:
运行kleopatra程序,新建密钥对,本人填的明码要记住,前面有用。

命令模式:
生成key:

gpg --gen-key

Real name: 名字
Email address: 邮箱(本人的邮箱
You selected this USER-ID:
Change (N)ame, (E)mail, or (O)kay/(Q)uit? o
之后往下,会让你输出用户名和邮箱,还有一个Passphase(明码输出两次,务必牢记,后续要用到)

查看公钥:

gpg --list-keys

pub rsa2048 2020-06-30 [SC] [expires: 2022-06-30]

  85B594371E0A38D70243B1E927EDC1D952E45334

uid [ultimate] aaa mailto:11111111@qq.com
sub rsa2048 2020-06-30 [E] [expires: 2022-06-30]

公布公钥:pub 上面那一长串就是key

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 85B594371E0A38D70243B1E927EDC1D952E45334

4. 配置maven settings.xml

  <servers>
      <server>
        <id>ossrh</id>
        <username>SonaType账号</username>
        <password>SonaType明码</password>
      </server>
  </servers>
 
  <profiles>
    <profile>
      <id>ossrh</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <!--装置的GnuPG地位-->
        <gpg.executable>C:/Program Files (x86)/GnuPG/bin/gpg.exe</gpg.executable>
        <gpg.passphrase>生成秘钥时输出的明码</gpg.passphrase>
      </properties>
    </profile>
  </profiles>

5. 配置我的项目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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>

    <groupId>com.ddd.ccc</groupId>
    <artifactId>aaa</artifactId>
    <version>1.0.0</version>

    <name>${project.artifactId}</name>
    <description>afdfdfsdfdfff</description>
    <url>https://</url>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
       ...
    </dependencies>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://www.opensource.org/licenses/mit-license.php</url>
            <distribution>repo</distribution>
        </license>
    </licenses>
    <scm>
        <url>https://gitee.com/***</url>
        <connection>https://gitee.com/***.git</connection>
        <developerConnection>https://gitee.com/***</developerConnection>
    </scm>
    <developers>
        <developer>
            <name>wuyun</name>
            <email>12345@qq.com</email>
            <url>https://gitee.com/***</url>
        </developer>
    </developers>
    <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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.7</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <!-- 是否主动公布--><autoReleaseAfterClose>false</autoReleaseAfterClose>
                </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>
                <configuration>
                    <show>private</show>
                    <nohelp>true</nohelp>
                    <charset>UTF-8</charset>
                    <encoding>UTF-8</encoding>
                    <docencoding>UTF-8</docencoding>
                    <additionalparam>-Xdoclint:none</additionalparam>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <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>

6. deploy

在你的我的项目下:mvn clean deploy
或者IDE中配置好方才的setting.xml,而后deploy,日志中呈现SUCCESS ,胜利了。

7. 公布

下面执行实现之后,登陆nexus:https://s01.oss.sonatype.org/…

点击上方的Close,会检测你的jar包是否存在问题,如果存在问题,点击下方的Activity即可查看具体的问题,照着问题修复即可。如果有问题要把原包删除,点击drop即可,再从新deploy。

检测实现后没问题后,上方的release就会变成可点击的状态,点击release后,会收到一份邮件。须要期待一会大略半小时才同步到maven仓库,大略好几个小时才能够能够在 https://search.maven.org/ 中搜到。

至此。已实现将我的项目公布至地方仓库。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理