Erlo

Java Maven项目推送到 Maven 中央仓库

2024-04-13 14:29:18 发布   20 浏览  
页面报错/反馈
收藏 点赞

准备阶段

namespace 域名认证

当需要在 sonatype 认证 com.xxx命名空间时,需要将 @.xxx.com 配置域名解析。

记录类型:TXT

文本内容:验证的 key。

file

file

GPG 公私钥生成

GPG 下载地址:https://www.gnupg.org/download/index.html

Mac 可以使用 brew install gpg直接安装

使用方式可参考:

生成证书

$ gpg --gen-key

file

file

查询证书

$ gpg --list-keys 
gpg: 正在检查信任度数据库
gpg: marginals needed: 3  completes needed: 1  trust model: pgp
gpg: 深度:0  有效性:  1  已签名:  0  信任度:0-,0q,0n,0m,0f,1u
gpg: 下次信任度数据库检查将于 2027-04-06 进行
[keyboxd]
---------
pub   ed25519 2024-04-06 [SC] [有效至:2027-04-06]
      ABC
uid             [ 绝对 ] xxx 
sub   cv25519 2024-04-06 [E] [有效至:2027-04-06]

上传公钥到公钥管理服务器

$ gpg --keyserver keyserver.ubuntu.com --send-keys ABC
gpg: 正在发送密钥 ABC 到 hkp://keyserver.ubuntu.com

如果报错 gpg: keyserver send failed: No route to host可以参考该文章上传公钥:https://vayne.cc/2022/03/13/gpg/

推送阶段

pom.xml 文件配置

配置 url

    https://github.com/xxx/yyy

配置 license

    
        
            The Apache Software License, Version 2.0
            http://www.apache.org/licenses/LICENSE-2.0.txt
            repo
        
    

配置 issueManagement

    
        github
        https://github.com/xxx/yyy/issues
    

配置 SCM

    
        scm:git:https://github.com/xxx/yyy.git
        scm:git:https://github.com/xxx/yyy.git
        https://github.com/xxx/yyy
    

配置开发者信息

    
        
            xxx
            xxx@zzz.com
            https://github.com/xxx
        
    

通用插件配置

    
        
            
                org.codehaus.mojo
                flatten-maven-plugin
                1.5.0
                
                    true
                    oss
                
                
                    
                        flatten
                        process-resources
                        
                            flatten
                        
                    
                    
                        flatten.clean
                        clean
                        
                            clean
                        
                    
                
            

            
            
                org.apache.maven.plugins
                maven-source-plugin
                3.1.0
                true
                
                    
                        attach-sources
                        
                            jar
                        
                    
                
                
                    true
                    true
                
            

            
                org.apache.maven.plugins
                maven-javadoc-plugin
                3.1.0
                true
                
                    
                        bundle-sources
                        package
                        
                            jar
                        
                    
                
                
                    1024
                    UTF-8
                    protected
                    true

                    
                    false
                    none
                
            
        
    

Maven 上传插件配置

    
        
            release
            
                
                    
                        org.apache.maven.plugins
                        maven-gpg-plugin
                        1.6
                        
                            
                                sign-artifacts
                                verify
                                
                                    sign
                                
                            
                        
                        
                            
                                
                                --pinentry-mode
                                loopback
                            
                        
                    
                    
                    
                        org.sonatype.central
                        central-publishing-maven-plugin
                        0.4.0
                        true
                        
                            central
                            true
                            true
                            
                                xxx-yyy
                            
                        
                    
                
            
        
    

settings.xml 文件配置

  
    
      central
      xxx
      yyy
    
  
  
    
      gpg
      
        true
      
      
        gpg
        xxx@zzz.com
        passphrase
        true
      
    
  

执行构建并上传

$ mvn clean deploy -Prelease 

上传结果

file

报错参考

  • Javadocs must be provided but not found in entries:需要提供 Javadoc
  • License information is missing:需要提供 license 信息
  • Project URL is not defined:需要定义项目 URL 信息
  • SCM URL is not defined:需要定义 SCM 信息
  • version cannot be a SNAPSHOT:Maven 中央仓库不支持推送快照版本

参考文档

分享并记录所学所见

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认