发布自己的maven依赖到中央仓库

1、注册一个https://issues.sonatype.org/的账号

在这里插入图片描述在这里插入图片描述
密码很复杂,建议拿个小本本记下来
进去之后点击创建

在这里插入图片描述
点击新建一个项目,有时候直接进去就可以创建,注意问题类型要为new project
在这里插入图片描述
概要和描述正常写就行,groupid为域名,我是在github上建了个仓库,因此填了github的groupid。
project url就填github地址,scm url就填github地址后加.git

在这里插入图片描述
点击创建就可以了,等待回复,我等了十来分钟。

2、安装并配置GPG

下载Gpg4win 3.1.5秘钥生成工具 下载跳转
一个傻瓜式的秘钥生成工具,正常生成就可以,记住passphrase,生成后点击发布:
在这里插入图片描述

3、配置maven的setting.xml

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

4、配置项目pom.xml文件

distributionManagement节和maven-compiler-plugin节的配置信息根据自己的实际情况做修改。

     <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
    <scm>
        <connection>scm:git:https://github.com/zhao458114067/repository-util.git</connection>
        <url>git:https://github.com/zhao458114067/repository-util</url>
    </scm>
    <developers>
        <developer>
            <name>zx</name>
            <email>zhaoxu1@supcon.com</email>
            <roles>
                <role>Developer</role>
            </roles>
            <timezone>+8</timezone>
        </developer>
    </developers>
   <profiles>
        <profile>
            <id>release</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/java</directory>
                        <includes>
                            <include>**/*.properties</include>
                            <include>**/*.sample</include>
                        </includes>
                    </resource>
                </resources>
                <plugins>
                    <!-- source包 -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>3.0.0</version>
                        <configuration>
                            <attach>true</attach>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- 生成doc文档 -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>attach-javadocs</id>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
        <distributionManagement>
        <repository>
            <id>ossrh</id>
            <name>Sonatype Nexus Snapshots</name>
            <url>https://s01.oss.sonatype.org/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>ossrh</id>
            <name>Nexus Release Repository</name>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

5、发布

mvn clean deploy -Darguments=“gpg.passphrase=私钥值”,私钥值为gpg程序生成的passphrase“密匙设置”值

注意groupid与创建问题时的groupid保持一致

第一次部署需要设置distributionManagement为以下内容

<distributionManagement>
        <repository>
            <id>ossrh</id>
            <name>Sonatype Nexus Snapshots</name>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2</url>
        </repository>
        <snapshotRepository>
            <id>ossrh</id>
            <name>Nexus Release Repository</name>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots//</url>
        </snapshotRepository>
    </distributionManagement>

version需要设置如下:

<version>1.0-SNAPSHOP</version>

上传成功如下:
在这里插入图片描述
搜索即可以看到自己的项目
在这里插入图片描述
**https://repo1.maven.org/maven2/

https://mvnrepository.com/
也可以查,但是同步比较慢大概需要一两个小时才能查到

6、最后就是项目中使用:

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值