Maven发布自己项目到maven中央仓库

目录

1. sonatype网站相关

1.1  注册sonatype网站账号

1.2  登录后,新建问题

 3. 配置maven--setting.xml

4. 配置maven--pom.xml

4.1 添加个人信息

4.2 添加开源版权信息

4.3 添加scm信息

4.4 添加插件

4.4 添加build

5. 下载GPG加密

5.1 安装Gpg4Win

5.2 创建密钥对

 5.3 验证版本

5.4 查看已生成的公私要信息

 5.5 发送公钥信息到ubuntu.com服务器

 5.6 查询是否发送成功

 5.7 发送公钥异常:gpg: keyserver send failed: Unknown error

6. 上传到maven中央仓库

6.1 命令行:

6.2 idea 执行

7 发布结果


1. sonatype网站相关

1.1  注册sonatype网站账号

Sign up for Jira - Sonatype JIRA

1.2  登录后,新建问题

 

 

新建后,等待工作人员评论

 

如果评论这样的话,在github上创建一个对应空项目。

 

这样就是认证通过了,可以上传项目到中央仓库。

 3. 配置maven--setting.xml

 在 <servers>标签下添加


	<server>
		<id>ossrh</id>
		<username>你sonatype账号</username>
		<password>sonatype 密码</password>
	</server>

4. 配置maven--pom.xml

4.1 添加个人信息

<name>object-comparator</name>
<description>Java object property value comparator</description>
<url>https://github.com/jinchunzhao/object-comparator</url>

<developers>
    <developer>
      <id>jinchunzhao</id>
      <name>jinchunzhao</name>
      <email>15136708953@163.com</email>
    </developer>
</developers>

4.2 添加开源版权信息

根据项目的开源协议

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

4.3 添加scm信息

<scm>
    <connection>https://github.com/jinchunzhao/object-comparator.git</connection>
    <url>https://github.com/jinchunzhao/object-comparator</url>
  </scm>

4.4 添加插件

distributionManagement 下面的id必须要和你 maven settings.xml里面的id配置的一模一样

<profiles>
    <profile>
      <id>release</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <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>
            <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.6</version>
            <executions>
              <execution>
                <phase>verify</phase>
                <goals>
                  <goal>sign</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <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>
            </configuration>
          </plugin>
          <!--Release -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.1</version>
          </plugin>
          <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>ossrh</serverId>
              <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
              <autoReleaseAfterClose>true</autoReleaseAfterClose>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-scm-plugin</artifactId>
            <version>1.8.1</version>
          </plugin>
        </plugins>
      </build>
      <!-- 这里配置的ossrh要与settings.xml的一致,不然发布会出错 -->
      <distributionManagement>
        <snapshotRepository>
          <id>ossrh</id>
          <name>Sonatype Nexus Snapshots</name>
          <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
        </snapshotRepository>
        <repository>
          <id>ossrh</id>
          <name>Nexus Release Repository</name>
          <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
      </distributionManagement>
    </profile>
  </profiles>

4.4 添加build

<build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>8</source>
          <target>8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

5. 下载GPG加密

Gpg4win - Download Gpg4win

5.1 安装Gpg4Win

傻瓜式安装

5.2 创建密钥对

 5.3 验证版本

ggp --version

 

5.4 查看已生成的公私要信息

gpg --list-keys

 

 5.5 发送公钥信息到ubuntu.com服务器

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 刚刚生成的公钥 

 5.6 查询是否发送成功

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 刚刚发送的公钥 

 5.7 发送公钥异常:gpg: keyserver send failed: Unknown error

适用我的解决办法是:

执行下面两个命令

gpgconf --kill dirmngr

dirmngr --debug-all --daemon --standard-resolver

在另一个终端上运行推送公钥命令就可以了。

6. 上传到maven中央仓库

6.1 命令行:

mvn clean deploy -P release -Dmaven.test.skip=true
# 这里的 -P release与pom.xml中的标签一致
<profile>
    <id>release</id>
</profile>

6.2 idea 执行

执行成功

7 发布结果

表明已经发布成功了。

这样就可以到 Maven Central Repository Search 去查刚刚发布的项目,如果没有查到也关系,同步需要一段时间。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Hi,all

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值