github项目的jar包上传到maven中央仓库

目录

前言

  • 前面写过一篇把Jar包上传到GitHub仓库,有个弊端就是必须先声明repository地址才能把jar包拉下来,这次直接把jar包上传到中央仓库,就没这个烦恼了,直接声明pom坐标即可。

准备

中央仓库

  • 打开中央仓库 https://central.sonatype.com/ 注册帐号,建议直接使用GitHub登陆,Namespace会自动验证好。

  • pom.xml的groupId就写这个已验证的Namespace

  • 创建token

  • 配置到maven settings.xml文件中

xml 复制代码
 ...省略...
  <servers>
    <server>
      <id>central</id>
      <username>生成的Token用户名</username>
      <password>生成的Token密码</password>
    </server>
    ..省略...
  </servers>
 ...省略... 

生成 GPG 密钥

上传到中央仓库的二进制文件都必须经过签名,以证明它们没有被篡改

shell 复制代码
gpg --full-generate-key

密钥类型: RSA and RSA

密钥长度: 4096

其余按自己情况填写

  • 上传公钥
shell 复制代码
#先查看 ID
gpg --list-keys --keyid-format LONG
  • 上传到公钥服务器( Key ID是 rsa4096/ 后面16个字符)
shell 复制代码
gpg --keyserver keyserver.ubuntu.com --send-keys 你的KeyID

项目配置

xml 复制代码
  <groupId>io.github.1030907690</groupId>
    <artifactId>flink-sql-connector-elasticsearch8</artifactId>
    <version>${revision}</version>
    <name>${project.artifactId}</name>
    <url>https://github.com/1030907690/flink-sql-connector-elasticsearch8</url>
    <description>flink-sql-connector-elasticsearch8</description>


    <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>Zhou Zhongqing</name>
            <email>g1030907690@gmail.com</email>
            <organization>Zhou Zhongqing</organization>
            <organizationUrl>https://github.com/1030907690</organizationUrl>
        </developer>
    </developers>

   <scm>
        <connection>scm:git:git://github.com/1030907690/flink-sql-connector-elasticsearch8.git</connection>
        <developerConnection>scm:git:ssh://github.com:1030907690/flink-sql-connector-elasticsearch8.git</developerConnection>
        <url>https://github.com/1030907690/flink-sql-connector-elasticsearch8/tree/main</url>
    </scm>

    <properties>
        ...省略...
        <java.version>17</java.version>
        <revision>1.0.3</revision>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
<dependencies>
...省略依赖信息...
</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <exclude>org.apache.flink:*</exclude>
                                    <exclude>org.slf4j:*</exclude>
                                    <exclude>log4j:*</exclude>
                                </excludes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <!--     生成源javadocs文件       -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.11.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <!--     生成源文件       -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.6.3</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--    签名插件        -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--    Maven插件发布    -->
            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.4.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                    <tokenAuth>true</tokenAuth>
                </configuration>
            </plugin>
            <!-- 替换变量 ${revision} -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>1.5.0</version>
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>resolveCiFriendliesOnly</flattenMode>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
  • 注意:每个类要有注释,否则执行deploy时会报错:

上传jar包

  • 我将版本号改为1.0.4
  • 点击deploy
  • 中途会弹窗输入密钥密码。
  • 上传成功后在中央仓库后台就能看到如下信息。
  • 点击Publish按钮后,稍侯再搜索便能查到此版本的pom坐标了。

其他

  • 如果你有两台电脑,都想使用同一个密钥,可以使用Kleopatra先备份私钥,然后另一台电脑再导入即可使用。

参考

相关推荐
comcoo5 小时前
龙虾 AI OpenClaw Windows 本地部署,5 分钟落地专属私有化 AI 智能体
github·开源软件·龙虾ai·open claw部署
德宏大魔王(AI自动回关)7 小时前
鱿鱼云码公测:基于YOLOv26+消息队列的高性能打码平台
yolo·github·打码平台·鱿鱼云码
2601_961194028 小时前
2026六级词汇PDF下载|大学英语六级单词表+音频PDF
windows·git·eclipse·pdf·github
xuhe210 小时前
AI时代一届计算机学生本科生 四年生活 保研记录: 四非本科 -> 中流985
ai·github·科研
wyhwust10 小时前
如何让maven帮我们去下载合适的包
java·maven
jiayong2310 小时前
Maven clean 报错与 Maven Profile 机制总结
java·maven
小橙讲编程11 小时前
一键给 AI Agent 装上「互联网眼睛」:Agent Reach 深度解析与实战指南
人工智能·开源·github·ai编程
无人生还别怕12 小时前
搭建gitlab服务并接入openldap认证
git·gitlab·github·openldap·ldap·统一认证
小二·12 小时前
Python 异步编程深度解析:Async/Await 实战
网络·python·github
C++ 老炮儿的技术栈14 小时前
如何利用 OpenCV 将图像显示在对话框窗口上
c语言·c++·人工智能·qt·opencv·计算机视觉·github