美文网首页
上传自己的jar包到maven中央仓库

上传自己的jar包到maven中央仓库

作者: 武小寺 | 来源:发表于2020-11-30 19:01 被阅读0次

申请账号

新建项目(github or gitee)

  • 新建项目,上传到github或者gitee
  • 下面创建工单的git源使用

申请权限

  • 登录上面的账号,创建工单


    image.png
  • 根据工单的要求,进行对应的工作,最终工单变为已修复即可

加密验签

  • 下载gpg来生产秘钥对

    查看是否安装成功
    gpg --version
    
    生成密钥对
    gpg --gen-key
    
    查看公钥
    gpg --list-keys
    
    将公钥发布到PGP密钥服务器
    gpg --keyserver hkp://pool.sks-keyservers.net --send-keys 公钥ID
    
    查询公钥是否发布成功
    gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys
    
  • 创建秘钥对

  • 相关参数
    name: XXXX
    mail: xxxx@163.com
    password:  xxxxx
    
    gpg: /Users/wuwenjie/.gnupg/trustdb.gpg:建立了信任度数据库
    gpg: 密钥 D6BFCDEA66953384 被标记为绝对信任
    gpg: 目录‘/Users/wuwenjie/.gnupg/openpgp-revocs.d’已创建
    gpg: 吊销证书已被存储为‘/Users/wuwenjie/.gnupg/openpgp-revocs.d/233FA1BE7CACA65156AFCD0ED6BFCDEA66953384.rev’
    公钥和私钥已经生成并被签名。
    
    pub   rsa2048 2020-04-26 [SC] [有效至:2022-04-26]
          233FA1BE7CACA65156AFCD0ED6BFCDEA66953384
    uid                      kuixin <zjkxtech@163.com>
    sub   rsa2048 2020-04-26 [E] [有效至:2022-04-26]
    

配置maven与项目的pom文件

maven setting.xml

<server>
    <id>oss</id>
    <username>kx</username>
    <password>oRVJqmU30Rbc%</password>
</server>
pom文件

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.gitee.xxx</groupId>
    <artifactId>xx-tools</artifactId>
    <version>1.0</version>
    <name>xx-tools</name>
    <description>Spring Boot tools for phone,ip</description>
    <url>https://gitee.com/xxx/xx-tools</url>
    <!-- 开源签名证书 -->
    <licenses>
        <license>
            <name>The MIT License</name>
            <url>http://opensource.org/licenses/MIT</url>
        </license>
    </licenses>
    <!-- 开发人员信息 -->
    <developers>
        <developer>
            <name>xxxx</name>
            <email>xxxx@163.com</email>
        </developer>
    </developers>

    <!-- 仓库信息 -->
    <scm>
        <connection>scm:git:git://gitee.com:xxxx/xx-tools.git</connection>
        <developerConnection>scm:git:git://gitee.com:xxxx/xx-tools.git</developerConnection>
        <url>https://gitee.com/xxxx/xx-tools</url>
    </scm>


    <dependencies>


    </dependencies>
    <build>
        <plugins>
            <!-- 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.10.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- GPG -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <distributionManagement>
        <snapshotRepository>
            <id>oss</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>oss</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

</project>

打包上传成功

  • 使用maven命令,直接进行打包即可


    image.png
  • 发布


    image.png

错误处理

gpg signing failed inappropriate ioctl for device Mac

$ brew install pinentry-mac
$ echo "pinentry-program /usr/local/bin/pinentry-mac" >> ~/.gnupg/gpg-agent.conf
$ killall gpg-agent

相关文章

网友评论

      本文标题:上传自己的jar包到maven中央仓库

      本文链接:https://www.haomeiwen.com/subject/qurdwktx.html