• maven发布jar到中央仓库


    maven发布jar到中央仓库

    一、注册JIRA帐号

    ​ 地址:https://issues.sonatype.org/secure/Dashboard.jspa

    注意:密码需要至少8位,同时有大小写字母,特殊字符和数字

    二、创建issue

    三、等待审核

    域名问题,需要groupId的域名部分属于自己的域名,在这里使用com.github.duojin

    根据一系列对话的指引解决所有问题,地址https://issues.sonatype.org/browse/OSSRH-53957

     

    四、gpg 环境安装

    gpg的主要作用是生成密钥对,会用于后续我们组件发布的校验。

    1、下载地址: https://www.gnupg.org/download/, 安装时会附带安装UI程序kleopatra

    2、在安装完成后,运行kleopatra程序,新建密钥对

    image-20191218230105776

    3、导出证书 发布证书

     五、maven 全局配置

    默认的maven配置文件为用户目录下的 .m2/setting.xml或自己配置后的目录文件

    添加服务器验证

    <server>
        <id>sonatype_releases</id>
        <username>your user name</username>
        <password>your password</password>
    </server>
    <server>
        <id>sonatype_snapshots</id>
        <username>your user name</username>
        <password>your password</password>
    </server>
      • 用户名和密码是第一步中注册的JIRA的

      • 配置gpg验证命令

        <settings>
          <profiles>
            <profile>
              <id>gpg</id>
              <properties>
                <gpg.executable>gpg</gpg.executable>
                <gpg.passphrase>your password</gpg.passphrase>
              </properties>
            </profile>
          </profiles>
          <activeProfiles>
            <activeProfile>gpg</activeProfile>
          </activeProfiles>
        </settings>

        六、项目中的maven配置

        • 在项目的pom.xml文件中,配置相应的开源协议、仓库信息、开发人员信息和发布配置
          <!-- 开源签名证书 -->
          <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>
              <connection>scm:git@github.com:duojin/sms-spring-boot-project.git</connection>
              <developerConnection>scm:git@github.com:duojin/sms-spring-boot-project.git
              </developerConnection>
              <url>https://github.com/duojin/sms-spring-boot-project</url>
          </scm>
          <!-- 开发人员信息 -->
          <developers>
              <developer>
                  <name>ajoe.Liu</name>
                  <email>87893689@qq.com</email>
                  <organization>https://github.com/duojin</organization>
                  <timezone>+8</timezone>
              </developer>
          </developers>
          <!-- 发布管理信息 -->
          <distributionManagement>
              <repository>
                  <!-- 这里的id必须要和全局配置中的release id 一致 -->
                  <id>sonatype_releases</id>
                  <name>Nexus Release Repository</name>
                  <!-- 这里就是在创建issue成功后,对方回复的release发布地址-->
                  <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
              </repository>
              <snapshotRepository>
                  <!-- 这里的id必须要和全局配置中的snapshot id 一致 -->
                  <id>sonatype_snapshots</id>
                  <name>Nexus Snapshot Repository</name>
                  <!-- 这里就是在创建issue成功后,对方回复的snapshot发布地址-->
                  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
              </snapshotRepository>
          </distributionManagement>

          发布到maven中央仓库会要求我们在上传jar到同时,必须同步发布对应到Javadoc、source、asc(利用gpg生成到校验),所以需要在maven中添加以下构建插件

          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>3.8.1</version>
                      <configuration>
                          <source>1.8</source>
                          <target>1.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>
                          <!-- 这里的id必须要和全局配置中的release id 一致 -->
                          <serverId>sonatype_releases</serverId>
                          <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                          <!-- 如果希望发布后自动执行close和release操作,此处可以调整为true -->
                          <autoReleaseAfterClose>false</autoReleaseAfterClose>
                      </configuration>
                  </plugin>
                  <!-- 生成java source.jar -->
                  <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>
                          <aggregate>true</aggregate>
                          <charset>UTF-8</charset>
                          <encoding>UTF-8</encoding>
                          <docencoding>UTF-8</docencoding>
                          <!-- -Xdoclint:none maven忽视javadoc过程中警告和错误 -->
                          <additionalparam>-Xdoclint:none</additionalparam>
                      </configuration>
                      <executions>
                          <execution>
                              <id>attach-javadocs</id>
                              <goals>
                                  <goal>jar</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
                  <!-- 生成asc 校验文件 -->
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-gpg-plugin</artifactId>
                      <version>1.5</version>
                      <executions>
                          <execution>
                              <!-- 必须和配置中的gpg校验id一致 -->
                              <id>gpg</id>
                              <phase>verify</phase>
                              <goals>
                                  <goal>sign</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>

    七、打包发布jar到中央仓库

    • 执行以下命令进行发布(如果 pom.xml 中 autoReleaseAfterClose 的值为true,则脚本会自动完成在平台上close、release的操作,至此你将成功发布了,否则我们继续查看第3步)

    测试打包

    mvn clean package
    

     发布

    mvn clean release
    

    八、验证

    学习时的痛苦是暂时的 未学到的痛苦是终生的
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    dataGridView不选中第一行第一列的办法!
    C#唯一随机数 和 PadLeft、PadRight 补足位数
    SSRS 数值和日期格式
    Oracle SQL*Loader
    找不到请求的 .Net Framework Data Provider。可能没有安装
    ORA00837: Specified value of MEMORY_TARGET greater than MEMORY_MAX_TARGET
    oracle临时表空间 ORA01652:无法通过16(在表空间XXX中)扩展 temp 字段
    ORACLE恢复删除表或表记录
    Spring.Net Resource handler for the 'web' protocol is not defined.
    ASP.NET MVC ueditor图片上传失败问题
  • 原文地址:https://www.cnblogs.com/juanxincai/p/12886521.html
Copyright © 2020-2023  润新知