将自己项目发布到 maven 仓库

注册 Sonatype

注册 Sonatype

下载gpg并生成密钥

sh 复制代码
# 检查版本
gpg -version

# 生成密钥,会提醒你输入name和email,按提示输入两个属性值后,输入O结束。
gpg --gen-key

# 查看密钥
gpg --list-keys

# 发布公钥
gpg --keyserver keyserver.ubuntu.com --send-keys 刚刚生成的公钥
# 验证公钥(一般隔天才能验证出来)
gpg --keyserver keyserver.ubuntu.com --recv-keys 502D2321AB02BE29

导出私钥

sh 复制代码
gpg --armor --export-secret-keys 502D2321AB02BE29

修改 xml

创建用户令牌

直接写到 maven 的xml文件里

xml 复制代码
<settings>
    <servers>
        <server>
            <id>central</id>
            <username>GVnq6g</username>
            <password>oIQntX8k8xumEjOMIfSVF00BhGACHDR0Q</password>
        </server>
    </servers>
</settings>

在 pom 文件

xml 复制代码
<distributionManagement>
    <repository>
        <id>central</id>
        <url>https://central.sonatype.com/api/v1/publisher</url>
    </repository>
</distributionManagement>

完整pom模板

xml 复制代码
<?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">

    <groupId>io.github.k3109405015</groupId>
    <artifactId>yu-tool</artifactId>
    <version>1.0.0</version>

    <modelVersion>4.0.0</modelVersion>
    <packaging>jar</packaging>

    <name>nzfisl1v2o</name>
    <description>综合工具框架</description>
    <url>https://github.com/k3109405015/nzfisl1v2o.git</url>

    <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>GaoYu</name>
            <email>3109405015@qq.com</email>
        </developer>
    </developers>

    <scm>
        <connection>scm:git:git://github.com/k3109405015/nzfisl1v2o.git</connection>
        <developerConnection>scm:git:ssh://github.com/k3109405015/nzfisl1v2o.git</developerConnection>
        <url>https://github.com/k3109405015/nzfisl1v2o</url>
    </scm>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <distributionManagement>
        <repository>
            <id>central</id>
            <url>https://central.sonatype.com/api/v1/publisher</url>
        </repository>
    </distributionManagement>

    <dependencies>
        <!-- Lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.36</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>6.2.11</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>6.2.11</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-csv</artifactId>
            <version>2.21.2</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.6.0</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.3.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.7.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <autoPublish>true</autoPublish>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.2.7</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project> 
相关推荐
wh_xia_jun13 小时前
给小白的 Maven 命令行执行测试 完整指南
git·maven·intellij-idea
一条泥憨鱼14 小时前
详解MySQL事务(超详细版)
java·数据库·mysql·spring·maven·后端开发
小江的记录本2 天前
【Java基础】集合框架: ArrayList vs LinkedList 核心区别、扩容机制(附《思维导图》+《面试高频考点清单》)
java·数据库·python·mysql·spring·面试·maven
Oo_行者_oO2 天前
Maven 完全教程与实战指南
maven
小碗羊肉2 天前
Maven高级
java·开发语言·maven
zhougl9963 天前
Maven build配置 补
java·maven
それども4 天前
Gradle 构建疑难杂症 Could not find netty-transport-native-epoll-linux-aarch_64.ja
java·服务器·gradle·maven
huaiixinsi4 天前
Java 后端面试高频题整理(02)
java·开发语言·spring·面试·职场和发展·架构·maven