maven 中央仓库发布

Last updated on September 15, 2024 pm

🧙 Questions

发布jar到中央仓库

☄️ Ideas

申请账号
申请项目

申请项目 https://issues.sonatype.org/secure/Signup.jspa

申请项目

跟踪问题进度

跟踪问题进度

阿里云域名确认

获取te=xt Record

OSSRH-75860
https://issues.sonatype.org/browse/OSSRH-75860

创建案例域名

回应问题,等待回复

回应

回复

GPG安装
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <!-- 项目基础信息 -->
    <groupId>com.isxcode.star</groupId>
    <artifactId>star-common</artifactId>
    <version>0.0.1</version>
    <name>star-common</name>
    <url>https://github.com/ispong/spark-star</url>
    <description>star-common</description>

    <!-- 变量配置 -->
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <!-- 项目依赖 -->
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.22</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <!-- 许可证信息  -->
    <licenses>
        <license>
            <name>The Apache License, Version 2.0</name>
            <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>

    <!-- 开发者信息 -->
    <developers>
        <developer>
            <name>ispong</name>
            <email>ispong@outlook.com</email>
        </developer>
    </developers>

    <!-- 仓库信息 -->
    <scm>
        <connection>scm:git:git://github.com/ispong/spark-star.git</connection>
        <developerConnection>scm:git:ssh://github.com/ispong/spark-star.git</developerConnection>
        <url>https://github.com/ispong/spark-star</url>
    </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>

            <!-- 此插件会自动发布正式版本,不需要手动release -->
            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.7</version>
                <extensions>true</extensions>
                <configuration>
                    <!-- ispong :) 和settings.xml server标签内id保持一致  -->
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            
            <!-- 给文件添加gpg加密,发布正式版本必须要阳台要验证gpg -->
            <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>
                        <configuration>
                            <executable>gpg</executable>
                            <keyname>0x7219EB0C</keyname>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- 生成项目source文件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- 生成项目docs文件 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
修改maven全局settings.xml

Note:
此处需要添加一开始注册的账号密码
id中输入的值必须和项目中pom.xml中 distributionManagement.snapshotRepository.id 保持一致

<servers>
    <server>
        <id>ossrh</id>
        <username>${username}</username>
        <password>${password}</password>
    </server>
</servers>
发布jar到中央仓库
mvn clean package deploy

maven 中央仓库发布
https://ispong.isxcode.com/spring/maven/maven 中央仓库发布/
Author
ispong
Posted on
December 3, 2021
Licensed under