将组件发布到maven中央仓库

1,注册账号并登录
https://issues.sonatype.org/secure/Signup!default.jspa
2,点击右上角Create创建一个Issue
Project 选择 Community Support - Open Source Project Repository Hosting
Issue Type 默认 New Project
Summary 写 Artifact ID
Group Id 倒着写域名
Project URL 写代码仓库的地址
SCM url 上面的地址.git
其他不用写
3, 创建号Issue后,等对方的Comment,会有个

To register this Group Id you must prove ownership of the domain xxx域名. Please complete the following steps to continue:

Add a DNS TXT record to your domain with the text: OSSRH-83925. Please read https://central.sonatype.org/faq/how-to-set-txt-record/
Edit this ticket and set Status to Open.

More info: https://central.sonatype.org/publish/

验证域名后,回复他 I have added a text record to DNS.
再等他的Comment,会有个

Congratulations! Welcome to the Central Repository!
xxx域名 has been prepared, now user(s) tanmingxin can:
Publish snapshot and release artifacts to s01.oss.sonatype.org
Have a look at this section of our official guide for deployment instructions:
https://central.sonatype.org/publish/publish-guide/#deployment

4, 重点来了。
开始修改pom.xml
<version>0.0.1-SNAPSHOT</version> 这个不能带-SNAPSHOT,不然不能公开发布到中央仓库
添加

<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>
<developers>
    <developer>
        <name>xxx</name>
        <email>xxx@qq.com</email>
        <organization>xxx</organization>
        <url>代码地址</url>
    </developer>
</developers>
<scm>
    <url>代码地址</url>
    <connection>代码地址.git</connection>
</scm>
<distributionManagement>
    <snapshotRepository>
        <id>ossrh</id>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
    </snapshotRepository>
    <repository>
        <id>ossrh</id>
        <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
</distributionManagement>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <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>
            <executions>
                <execution>
                    <id>attach-javadocs</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-gpg-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <id>sign-artifacts</id>
                    <phase>verify</phase>
                    <goals>
                        <goal>sign</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>false</autoReleaseAfterClose>
            </configuration>
        </plugin>
    </plugins>
</build>

5, 修改 Maven settings.xml
添加



<settings>
  <servers>
    <server>
      <id>ossrh</id>
      <username>your-jira-id</username>
      <password>your-jira-pwd</password>
    </server>
  </servers>
</settings>

6,生成密钥,这个一定要,不然不能发布。
下载地址:https://www.gpg4win.org/download.html
图形界面生成一个,右击证书在服务器上发布。
7,发布

mvn clean deploy

没有mvn的吧,去apache下载一个,设置好path,然后去代码目录执行上面的命令发布。

set path=%path%;C:\Users\tanmingxin\Downloads\apache-maven-3.8.6-bin\apache-maven-3.8.6\bin

8,去这个地址https://s01.oss.sonatype.org/#stagingRepositories登录点击上面的Release
然后会收到一封邮件通知,Issue中也会收到Comment
Central sync is activated for net.eudu. After you successfully release, your component will be available to the public on Central https://repo1.maven.org/maven2/, typically within 30 minutes, though updates to https://search.maven.org can take up to four hours.

最后修改:2022 年 08 月 26 日
如果觉得我的文章对你有用,请随意赞赏