【教程】如何上传依赖到maven中央仓库并且引入至pom文件

进入到Maven Central: Publishing (sonatype.com)网页并且使用github账号登录:

github新建repository :你的github用户名.github.io

中央仓库新建nameSpace :io.github.github用户名

安装gpg,获取指纹密钥:

Gpg4win - Download Gpg4win

安装时记住安装目录地址:

 查看指纹密钥,设置gpg密码(后面要用):

添加配置到上传项目pom文件:

<groupId>io.github.z19235</groupId>
  <artifactId>myapi-common</artifactId>
  <version>0.0.1</version>
  <packaging>jar</packaging>

  <name>myapi-common</name>
  <url>https://github.com/Z19235/myapi-common</url>
    <scm>
        <url>https://github.com/Z19235/myapi-common</url>
        <connection>scm:git:https://github.com/Z19235/myapi-common.git</connection>
        <developerConnection>scm:git:https://github.com/Z19235/myapi-common.git</developerConnection>
    </scm>

    <developers>
        <developer>
        <!--此处填写gpg用户id-->
            <id>dell</id>
            <!--此处填写gpg用户名-->
            <name>dell</name>
            <!--此处填写gpg邮箱-->
            <email>1923532529@qq.com</email>
            <url>https://github.com/github用户名/myapi-common</url>
            <timezone>+8</timezone>
        </developer>
    </developers>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
<build>
        <plugins>
            <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>
            <!-- Source -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Javadoc -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <configuration>
                    <additionalparam>-Xdoclint:none</additionalparam>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Javadoc -->
            <!-- 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>

            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.5.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>central</id>
            <url>https://central.sonatype.com/</url>
        </snapshotRepository>
    </distributionManagement>

进入IDEA,打开Setting中的Maven设置项,找到本机Maven配置文件setting.xml地址:

添加Maven配置至setting.xml:

 <profiles>
        <profile>
            <id>central</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!--此处填写gpg安装地址-->
                <gpg.executable>F:\computer\GnuPG\bin\gpg</gpg.executable>
                <!--此处填写gpg密码-->
                <gpg.passphrase>***</gpg.passphrase>
            </properties>
        </profile>
    </profiles>

获取token:

复制并添加入setting.xml:

最终格式:

<servers>
    <server>
	<id>central</id>
	<username>gXeZ3lod</username>
	<password>X/vW/kHEzJMOAmt2Azrt7YehcOcEIE1u8TEZBRuzoap2</password>
    </server>
</servers>

<profiles>
        <profile>
            <!-- id固定写为central -->
            <id>central</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <gpg.executable>F:\computer\GnuPG\bin\gpg</gpg.executable>
                <gpg.passphrase>之前设置的gpg密码</gpg.passphrase>
            </properties>
        </profile>
</profiles>

注意:Maven配置文件setting.xml修改完记得点保存

选择上传项目点击deploy(注意:每次上传前都要重新复制userName和passWord否则报错401):

 运行结果如下:

 点击Publish发布:

查看依赖上传情况:

查询依赖:

调用依赖成功:

参考博客出处:

2024年发布jar到国外maven中央仓库最新教程_io.gitee.bigbigfeifei-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值