温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

maven如何发布jar到中央仓库

发布时间:2021-12-14 17:27:33 来源:亿速云 阅读:198 作者:iii 栏目:大数据

本篇内容主要讲解“maven如何发布jar到中央仓库”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“maven如何发布jar到中央仓库”吧!

1、下载 gpg4win

2、gpg --full-generate-key 或者 gpg --gen-key 生成秘钥

C:\WINDOWS\system32>gpg --gen-key
gpg (GnuPG) 2.0.30; Copyright (C) 2015 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、数字签名算法也是RSA)
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 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: Ron   #输入姓名
Name must be at least 5 characters long  #姓名至少为5个字符
Real name: ron.zheng   #输入姓名
Email address: ron.zheng@tfschange.com  #输入邮箱地址
Comment: tfs #输入备注
You selected this USER-ID:
    "ron.zheng (tfs) <ron.zheng@tfschange.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o  #选择OK
You need a Passphrase to protect your secret key.  #弹出口令输入界面

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: key 0452FE75 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   2048R/0452FE75 2019-03-28
      Key fingerprint = 65B4 846F 7E63 A32B 34E3  A9FB C99D B8B9 0452 FE75
uid       [ultimate] ron.zheng (tfs) <ron.zheng@tfschange.com>
sub   2048R/488F27D2 2019-03-28


//输入命令查看生成的秘钥
gpg --list-secret-keys --keyid-format LONG
sec   rsa2048/XXXXXXXXX 2020-09-22 [SC]
      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
uid                 [ultimate] fashionbrot (描述) <fashionbrot@163.com>
ssb   rsa2048/xoxoxoxoxo 2020-09-22 [E]

//然后公钥上传服务器  (XXXXXXXXX)是sec    rsa2048/后面的
gpg --keyserver hkp://pool.sks-keyservers.net:11371 --send-keys XXXXXXXXX
gpg --keyserver keyserver.ubuntu.com --send-keys XXXXXXXXX
gpg --keyserver pgp.mit.edu --send-keys XXXXXXXXX
gpg --keyserver keys.gnupg.net --send-keys XXXXXXXXX

maven 配置增加

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <excludePackageNames>com.facebook.thrift:com.facebook.thrift.*</excludePackageNames>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <configuration>
                            <doclint>none</doclint>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                    <!-- -Dgpg.passphrase='秘钥密码'或者-Darguments='gpg.passphrase=秘钥密码' -->
                </executions>
            </plugin>
        </plugins>
    </build>

运行maven 命令

mvn  -Dmaven.test.skip=true verify -Dgpg.passphrase="秘钥密码"

然后target 下会生成一下文件 mvn -Dmaven.test.skip=true verify -Dgpg.passphrase="秘钥密码"

mars-validated-1.0.3.pom
mars-validated-1.0.3.jar
mars-validated-1.0.3.jar.as
mars-validated-1.0.3.pom.asc
mars-validated-1.0.3-javadoc.jar
mars-validated-1.0.3-javadoc.jar.asc
mars-validated-1.0.3-sources.jar
mars-validated-1.0.3-sources.jar.asc

然后访问https://oss.sonatype.org/ 进行登录

左侧菜单选择 >Staging Upload

1、Upload Mode: 选择 Artifact(s) with a POM2、Select Pom to Upload 选择 mars-validated-1.0.3.pom上传3、Select Artifact(s) to Upload 选择以下7个文件一个一个的添加

mars-validated-1.0.3.jar
mars-validated-1.0.3.jar.as
mars-validated-1.0.3.pom.asc
mars-validated-1.0.3-javadoc.jar
mars-validated-1.0.3-javadoc.jar.asc
mars-validated-1.0.3-sources.jar
mars-validated-1.0.3-sources.jar.asc

4、 Upload Artifact(s) 上传

然后进入发布页面左侧 -》Staging Repositories

1、先刷新然后选择你上传的jar (比较慢多等会)直到出现 Release 按钮,才算是jar包发布成功。如果没有出现,则表示jar签名出现错误。最后选中jar Release 发布即可

发布成功后1~2天才能在中央仓库看到。1天后就可以下载到

到此,相信大家对“maven如何发布jar到中央仓库”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI