美文网首页
上传项目到Maven中央仓库

上传项目到Maven中央仓库

作者: PiggyGuoJY | 来源:发表于2019-03-09 23:01 被阅读0次

编者按

         笔者最近在github上开源了一个Excel格式文件解析工具 excel2javaBean , 应要求上传项目到Maven仓库。其中坎坷不表, 现记录上传过程以供未来查阅。


目录

一、 注册 Sonatype JIRA 用户并创建工单
二、 安装 GPG 并生成密钥
三、 配置项目pom.xml和本地Maven setting.xml
四、 部署、发布和查看

一、 注册 Sonatype JIRA 用户并创建工单

登陆Sonatype JIRA并注册用户

JIRA 用户名和密码后面(3.2)会用到

1.1 创建工单

创建工单
最终点击 Create 按钮创建工单

对于第四步,虽然在创建Maven项目时可以随意写Group Id,但最好使用真实拥有的域名或推荐的com.github.[github用户名]格式域名。

1.2 等待管理员回复

等待管理员回复

即使Group Id对应的域名属于你,也可能会质询,回复拥有即可。由于我确实没有申请域名guojy.com,所以选择变更。

变更域名并获得相关地址

二、 安装 GPG 并通过命令生成密钥

2.1 下载并安装GPG并验证命令可用 windows版下载链接

根据操作系统类型下载相应的GPG安装包
gpg --version

2.2 生成密钥并上传公钥到服务器

gpg --gen-key

弹出窗口要求输入的密语要记得, 后面(4.1)会用到

gpg --gen-key2 gpg --keyserver

三、 配置项目pom.xml和本地 Maven setting.xml

3.1 配置项目的pom.xml文件

    <!--这里以spring-cloud-gray为例-->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <tag>master</tag>
        <url>git@github.com:SpringCloud/spring-cloud-gray.git</url>
        <connection>scm:git:git@github.com:SpringCloud/spring-cloud-gray.git</connection>
        <developerConnection>scm:git:git@github.com:SpringCloud/spring-cloud-gray.git</developerConnection>
    </scm>

    <developers>
        <developer>
            <name>saleson</name>
            <email>qlichunyu@163.com</email>
            <organization>Spring Cloud中国社区</organization>
        </developer>
    </developers>

    <profiles>
        <profile>
            <id>sonatype-oss-release</id>
            <build>
                <plugins>
                    <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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <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.1</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>

            <distributionManagement>
                <snapshotRepository>
                    <!--对应setting.xml servers.server.id-->
                    <id>sonatype-nexus-snapshots</id>
                    <url>
                        https://oss.sonatype.org/content/repositories/snapshots
                    </url>
                </snapshotRepository>
                <repository>
                    <!--对应setting.xml servers.server.id-->
                    <id>sonatype-nexus-staging</id>
                    <url>
                        https://oss.sonatype.org/service/local/staging/deploy/maven2
                    </url>
                </repository>
            </distributionManagement>
        </profile>
    </profiles>

maven-gpg-plugin如果不易自动下载可以选择使用命令 mvn dependency:get -DrepoUrl=http://repo.maven.apache.org/maven2/ -Dartifact=org.apache.maven.plugins:maven-gpg-plugin:1.1 手动下载。

3.2 配置本地maven的setting.xml文件

  <servers>
    <server>
      <id>sonatype-nexus-snapshots</id>
      <username>JIRA 用户名</username>
      <password>JIRA 用户密码</password>
    </server>
    <server>
      <id>sonatype-nexus-staging</id>
      <username>JIRA 用户名</username>
      <password>JIRA 用户密码</password>
    </server>
  </servers>

四、 部署、发布、通知审批和查看

4.1 部署

mvn clean deploy -P -sonatype-oss-release -Darguments="gpg.passphrase=密语" -Dmaven.test.skip=true

命令执行的过程中会要求在命令行和弹出框中输入密语,输入即可;gpg会报warn,直接忽略;到deploy阶段,会上传不少文件,耐心等待即可。

4.2 发布

登陆nexus

nexus登陆地址,这里的用户名和密码和登陆jira的一样。

点击close后填写备注信息
release.JPG

4.3 通知审批

首次上传通知审批.JPG

收到回复后等待10分钟左右即可完成同步Maven中央库,同步到search.maven.org则需要2小时以上;这一步只在首次部署发布时进行,之后的部署发布只需完成到4.2即可到4.4查看。

4.4 查看

release完成后可以查看上传结果
在maven中央仓库中查看上传结果
在search.maven.org上查看上传结果

引用

1. 发布jar包到maven中央库

2. 将项目发布到 maven 中央仓库踩过的坑

3. GPG入门

相关文章

网友评论

      本文标题:上传项目到Maven中央仓库

      本文链接:https://www.haomeiwen.com/subject/eztjpqtx.html