将项目发布到Maven中央仓库

sonatype创建工单

登录sonatype

访问sonatype官网,登录创建工单,若没有账户密码,注册后登录。
在这里插入图片描述

创建工单

在这里插入图片描述
在这里插入图片描述
然后点击新建即可,若有自己的域名的话group Id可以填写为自己的域名地址。

*必填项

项目:Community Support - Open Source Project Repository Hosting
问题类型:new project
group id :域名或github用户地址(示例:com.github.xxx)
project url:项目地址(https://github.com/xxx/test)
SCM url:git项目地址(https://github.com/xxx/test.git)

创建完页面如下:
在这里插入图片描述
由于这是已创建完项目,是已解决状态,若是新建的话,为状态是:开放

验证git账号拥有权

项目创建完,会进行账号验证,在问题下方有个活动日志
在这里插入图片描述
请在github.com中,根据提示创建相应项目,创建完后,进行评论,审批人回复后即可进行项目发布。
在这里插入图片描述

项目发布

maven配置文件

打开 maven根目录\conf\settings.xml文件,在<servers></servers>新增以下代码

<server>
	<id>oss</id>
    <username>[sonatype账号]</username>
    <password>[sonatype密码]</password>
</server>

gpg加密

访问gpg官网,进行下载gpg加密软件,
在这里插入图片描述
gpg4win 下载安装后有可视化以及命令行两种操作,无脑下一步安装即可,可修改安装路径。

设置环境变量,找到安装目录项\GnuPG\bin\gpg.exe加入path环境变量

可视化操作

  1. 新建密匙对,输入名称及邮箱即可。
    在这里插入图片描述
  2. 点击下一步后,提示输入passphrase:八位密码,【请记住】 该密码,用于maven deploy
    在这里插入图片描述
  3. 生成完将密匙上传到目录服务即可。

命令行操作

  1. 打开命令行操作页面 win + r 输入cmd即可,查看环境变量是否配置好,输入gpg --version 进行版本查看,有以下界面继续操作,若无,请将gpg.exe加入环境变量
    在这里插入图片描述
  2. 生成key
# 生成公钥
gpg --gen-key
输入用户邮箱;

# 查询生成公钥
gpg --list-keys
将pub 后的公钥复制发送到服务器
gpg --keyserver hkp://keyserver.ubuntu.com:11371  公钥

# 查询发送结果
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys  公钥

返回
gpg: Total number processed: 1
gpg:              unchanged: 1
表示成功

项目pom文件配置

maven版本为3.5

<?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.github.xxx(之前填写的groupId)</groupId>
    <artifactId>【项目名】</artifactId>
    <version>【项目版本】(示例:1.0)</version>
    <packaging>pom</packaging>
    
    <name>【github 用户名】</name>
    <description>【项目描述】</description>
    <url>【git项目地址】</url>

    <properties>
    	<!-- 编码 -->
        <project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>utf-8</project.reporting.outputEncoding>
        
        <!-- junit版本 -->
        <junit.version>4.11</junit.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <issueManagement>
        <system>Github Issue</system>
        <url>【git issues】(例:https://github.com/用户名/项目名/issues)</url>
    </issueManagement>

	<!-- 许可 -->
    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
	
	<!-- 开发者信息 -->
    <developers>
        <developer>
            <name>开发者名称</name>
            <email>开发者邮箱</email>
        </developer>
    </developers>
	
	<!-- git项目地址 -->
    <scm>
        <url>https://github.com/用户名/项目名</url>
        <connection>https://github.com/用户名/项目名.git</connection>
        <developerConnection>scm:git:https://github.com/用户名/项目名</developerConnection>
    </scm>
    <build>
        <plugins>
            <!-- Source -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Javadoc -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <charset>UTF-8</charset>
                    <docencoding>UTF-8</docencoding>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        
                        <!-- 跳过doc 生成报错 -->
                        <!--<configuration>
                            <additionalJOption>-Xdoclint:none</additionalJOption>
                        </configuration>-->
                    </execution>
                </executions>
            </plugin>
            
            <!-- Gpg Signature -->
            <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>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>release</id>
            <distributionManagement>
                <snapshotRepository>
                    <!--id 要与setting.xml server id一致-->
                    <id>oss</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                </snapshotRepository>
                <repository>
                    <!--id 要与setting.xml server id一致-->
                    <id>oss</id>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
            <build>
                <pluginManagement>
                    <plugins>

                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-source-plugin</artifactId>
                            <version>3.0.1</version>
                            <executions>
                                <execution>
                                    <id>oss</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>jar-no-fork</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>

                        <plugin>
                            <groupId>org.sonatype.plugins</groupId>
                            <artifactId>nexus-staging-maven-plugin</artifactId>
                            <extensions>true</extensions>
                            <configuration>
                                <serverId>oss</serverId>
                                <nexusUrl>https://oss.sonatype.org/</nexusUrl>
                                <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            </configuration>
                        </plugin>
                    </plugins>
                </pluginManagement>
            </build>
        </profile>
    </profiles>
</project>

发布jar包

  1. idea可以找右边工具类maven找到项目相面的Lifecycle-deploy
    在这里插入图片描述
    进行发布或者采用命令行发布
  2. 命令行发布(与1 选一操作即可)
    mvn clean deploy -P
  3. 输入弹出的gpg密码即可
    在这里插入图片描述
  4. 发布成功后,请登录到nexus控制台进行操作。

nexus控制页面操作

1.登录Nexus Repository Manager,输入sonatype账号密码登录即可。
2. 点击bulid promotion -Staging Repositories,查看刚刚发布的项目
在这里插入图片描述
3. 关闭该项目,看是否能正常关闭。
在这里插入图片描述
若不能正常关闭,排除错误后进行关闭,成功关闭后在sonatype进行回复,组件已发布 successfully issued,等待审批人进行审批,通过审批后,过2个小时即可在中央仓库查找到你的项目。
在这里插入图片描述

中央仓库搜索地址:https://search.maven.org/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值