記錄一次提交開源JAR包到中央倉庫的過程

編寫開源工程

我此次要開源的mybatis.batch插件,用於簡化批量提交。 代碼地址:https://github.com/liuaixi200/mybatis-batch-parent.gitjava

申請提交到中央倉庫的用戶帳號

申請地址:https://issues.sonatype.org
申請完後,記住用戶名和密碼,該用戶名與密碼能夠用來登錄:oss.sonatype.org。git

建立issure

注意兩點: 項目選 : Community Support - Open Source Project Repository Hosting (OSSRH) 類型選: New Projectgithub

若是有本身的域名:groupId能夠用本身的域名 若是沒有本身的域名: groupId只能用com.github.xxx 或者io.github.xxredis

配置RSA密鑰

下載gpg,下載地址:https://www.gnupg.org/download/ 安裝完後,一般會用到如下命令apache

查看版本:  gpg --version

生成密鑰:ubuntu

gpg --full-gen-key
gpg (GnuPG) 2.2.15; Copyright (C) 2019 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048)
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y
GnuPG needs to construct a user ID to identify your key.

Real name: 用戶名
Email address: 開發者郵箱
Comment: 111
You selected this USER-ID:
    "liuax (111) <liuax00@gmail.com>"

查看生成的密鑰服務器

D:\Program Files (x86)\GnuPG\bin>gpg --list-key
gpg: checking the trustdb
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
C:/Users/liuax01/AppData/Roaming/gnupg/pubring.kbx
--------------------------------------------------
pub   rsa2048 2019-05-03 [SC]
      XXXXXXXXXXXXXXX99AF5C965487C95B2525ED50
uid           [ultimate] liuax (111) <liuax00@gmail.com>
sub   rsa2048 2019-05-03 [E]

將key上傳到服務器,最好如下3個都執行一遍,不然上傳release包時,會報找不到pub keymybatis

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

檢測是否上傳成功maven

gpg --keyserver hkp://keys.gnupg.net:11371 --recv-keys XXXXXXXXXXXXXXX99AF5C965487C95B2525ED50

配置pom.xml

添加name,description,url,licenses,developers,scmide

<name>mybatis.batch</name>
    <description>批量提交插件</description>
    <url>https://github.com/liuaixi200/mybatis-batch-parent</url>

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

    <developers>
        <developer>
            <name>liuax</name>
            <email>liuax00@gmail.com</email>
            <organization>liuaixi200</organization>
            <organizationUrl>https://github.com/liuaixi200</organizationUrl>
        </developer>
    </developers>

    <scm>
        <url>https://github.com/liuaixi200/mybatis-batch-parent.git</url>
    </scm>

添加 distributionManagement

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

添加profiles,如下插件缺一不可

<profiles>
        <profile>
            <id>release</id>
            <properties>
                <gpg.executable>gpg</gpg.executable>
                <gpg.passphrase>12345678</gpg.passphrase>
                <gpg.executable>D:\Program Files (x86)\GnuPG\bin\gpg.exe</gpg.executable>
                <gpg.homedir>C:/Users/liuax01/AppData/Roaming/gnupg</gpg.homedir>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-deploy-plugin</artifactId>
                        <version>2.8.2</version>
                        <executions>
                            <execution>
                                <id>default-deploy</id>
                                <phase>deploy</phase>
                                <goals>
                                    <goal>deploy</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.7</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>oss_sonatype</serverId>
                            <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <configuration>
                            <gpgArguments>
                                <gpgArgument>-Dgpg.passphrase=${gpg.passphrase}</gpgArgument>
                            </gpgArguments>
                        </configuration>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>

                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.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>
                            <aggregate>true</aggregate>
                            <charset>UTF-8</charset>
                            <encoding>UTF-8</encoding>
                            <docencoding>UTF-8</docencoding>
                            <additionalparam>-Xdoclint:none</additionalparam>
                        </configuration>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

setting中添加server

<server>
      <id>oss_sonatype</id>
      <username>liuax</username>
      <password>wb!SSaM!gC3XXXX</password>
    </server>

須要上傳時執行如下命令

mvn deploy -release

登錄oss.sonatype.org查看結果

回覆issue 若是是第一次上傳

相關文章
相關標籤/搜索