自己上传开源库到Maven

  1. 创建sonatype账号;提一个JIRA单,可以参考我的提单

    • 可能会有github的验证,按照JIRA单的评论进行操作即可
  2. 创建密钥

    • 密钥有分为私有密钥和公开密钥,私有私钥需要配置到项目中,公开密钥上传到服务器

    • 密钥类型选择RSA and RSA

    • windows安装gpg4win创建密钥,使用命令行操作示例,如下:(用gui操作默认密钥类型不是RSA and RSA,上传到服务器也有问题)

      # 生成密钥
      C:\Users\Administrator>gpg --full-generate-key
      gpg (GnuPG) 2.4.0; Copyright (C) 2021 g10 Code GmbH
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
      
      # 类型一定要选(1) RSA and RSA
      Please select what kind of key you want:
         (1) RSA and RSA
         (2) DSA and Elgamal
         (3) DSA (sign only)
         (4) RSA (sign only)
         (9) ECC (sign and encrypt) *default*
        (10) ECC (sign only)
        (14) Existing key from card
      Your selection? 1
      RSA keys may be between 1024 and 4096 bits long.
      What keysize do you want? (3072)
      Requested keysize is 3072 bits
      Please specify how long the key should be valid.
               0 = key does not expire
            <n>  = key expires in n days
            <n>w = key expires in n weeks
            <n>m = key expires in n months
            <n>y = key expires in n years
      Key is valid for? (0) 0
      Key does not expire at all
      Is this correct? (y/N) y
      
      GnuPG needs to construct a user ID to identify your key.
      
      Real name: wdp
      Email address: 927718579@qq.com
      Comment: wdp-gpg
      You selected this USER-ID:
          "wdp (wdp-gpg) <927718579@qq.com>"
      
      Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
      We need to generate a lot of random bytes. It is a good idea to perform
      some other action (type on the keyboard, move the mouse, utilize the
      disks) during the prime generation; this gives the random number
      generator a better chance to gain enough entropy.
      We need to generate a lot of random bytes. It is a good idea to perform
      some other action (type on the keyboard, move the mouse, utilize the
      disks) during the prime generation; this gives the random number
      generator a better chance to gain enough entropy.
      gpg: revocation certificate stored as 'C:\\Users\\Administrator\\AppData\\Roaming\\gnupg\\openpgp-revocs.d\\F7E901A90444D1A8B91EA9163CA132CF1D4A5B0A.rev'
      public and secret key created and signed.
      
      pub   rsa3072 2023-04-21 [SC]
            F7E901A90444D1A8B91EA9163CA132CF1D4A5B0A
      uid                      wdp (wdp-gpg) <927718579@qq.com>
      sub   rsa3072 2023-04-21 [E]
      
      # 创建私有密钥
      C:\Users\Administrator>gpg --export-secret-keys > secret.gpg
      # 将公开密钥上传到服务器
      C:\Users\Administrator>gpg --keyserver keyserver.ubuntu.com --send-keys
      
  3. 配置gradle脚本

    • 可以先本地生成一下,没有问题在上传到maven,脚本可以复制这个博客:

      https://blog.csdn.net/qq_20489601/article/details/123916777

  4. 发布

    进入maven管理后台, Staging Repositories --> open --> close --> release

  5. 使用:例如implementation 'io.github.dongpingwang:AndroidSerialPort:1.0.0'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要将 Maven 项目发布到 Maven 仓库,需要进行以下步骤: 1. 在 Maven 项目的 pom.xml 文件中添加发布仓库的信息,例如: ``` <distributionManagement> <repository> <id>my-repo</id> <name>My Repository</name> <url>http://myserver/repo/</url> </repository> </distributionManagement> ``` 2. 在 Maven 项目的根目录下执行以下命令,将项目打包成 jar 包: ``` mvn clean package ``` 3. 执行以下命令,将 jar 包发布到指定的仓库: ``` mvn deploy ``` 以上命令会将项目打包成 jar 包并上传到指定的仓库。如果没有指定仓库的用户名和密码,需要在 settings.xml 文件中添加: ``` <settings> <servers> <server> <id>my-repo</id> <username>my-username</username> <password>my-password</password> </server> </servers> </settings> ``` 其中,id 对应 distributionManagement 中的 repository id,username 和 password 对应仓库的登录信息。 注意,发布到 Maven 仓库需要具有相应的权限,如果是自己搭建的私有仓库,需要先配置好权限。 ### 回答2: Maven 是一个开源的项目管理工具,它可以帮助开发人员简化构建和管理 Java 项目的过程。Maven 支持将项目构建产物(例如:JAR 文件、WAR 文件等)发布到远程仓库中,以便其他项目可以方便地引用这些构建产物。 要将构建产物发布到 Maven 仓库,我们首先需要在项目的 Maven 配置文件 pom.xml 中指定远程仓库的地址和凭证信息。在 pom.xml 文件的 <distributionManagement> 节点中,我们需要配置 <repository> 节点的 <url> 子节点来指定仓库的地址,以及 <id> 子节点来指定仓库的唯一标识符。另外,我们还需要在 Mavensettings.xml 文件中配置仓库的凭证信息,以便能够正确地进行发布。 当配置完成后,我们可以使用 Maven 的 deploy 插件来执行构建产物的发布操作。我们可以通过命令行执行 "mvn deploy" 命令,或者在集成开发环境(IDE)中执行相应的 Maven 构建命令来触发发布操作。Maven 会将构建产物上传到远程仓库中,并且自动生成相应的元数据文件,用于标识发布的版本和构建产物的相关信息。 其他项目希望使用我们发布到仓库中的构建产物时,只需要在其相应的 pom.xml 文件中添加对该构建产物的依赖声明。根据配置的远程仓库地址和唯一标识符,Maven自动从远程仓库下载构建产物,并将其添加到当前项目的构建路径中。这样,其他项目就可以方便地引用和使用我们发布的构建产物了。 总之,使用 Maven 发布到仓库是一种方便的方式,能够让我们轻松地将构建产物分享给其他项目。通过正确配置远程仓库的地址和凭证信息,并使用 Maven 的发布命令,我们可以将构建产物成功地发布到仓库中,并让其他项目能够方便地引用和使用

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值