从零开始把项目发布到maven仓库中心

sonatype准备操作

  • 注册账号

    https://issues.sonatype.org

    1. 密码符号规范,并且工记住
  • 新建项目

    从零开始把项目发布到maven仓库中心_第1张图片

1. group id 如果你有com域名的所有权可以直接使用,如果不符合可以使用com.github.{账号名来定义}
2. 如果有问题管理员会在下方留言通知你如下文(github所有权验证)

然后等会有类似的通知发出,并按通知进行操作。

When choosing a groupId that reflects your project hosting, in this case, something like io.github.ants-double or com.github.ants-double would be correct. Also, please create a public repo called OSSRH-52139 to verify github account ownership.

然后你就创建对应的公有仓库,等创建成功后在些回复一下,看到如下评论前期准备工作就正式结束了

com.github.ants-double has been prepared, now user(s) antsdouble,Ants-double can:

Deploy snapshot artifacts into repository https://oss.sonatype.org/content/repositories/snapshots
Deploy release artifacts into the staging repository https://oss.sonatype.org/service/local/staging/deploy/maven2
Release staged artifacts into repository 'Releases'
please comment on this ticket when you promoted your first release, thanks

GPG的准备工作

  • windows安装gpg https://www.gpg4win.org/get-gpg4win.html,这里使用git命令行工具

  • 生成秘钥

    gpg --gen-key 按照提示输入姓名/邮箱,然后按O即可生成
  • 查看秘钥

    gpg --list-keys
  • 同步公钥

    gpg --keyserver http://keys.gnupg.net:11371/ --send-keys [xxxxxxxxx] 其中的[xxxxxxxxx],可用gpg --list-keys显示出来。

Maven准备工作

  • 更新setting.xml文件添加仓库

    
      sonatype-nexus-snapshots
      Sonatype账号
      Sonatype密码
    
    
      sonatype-nexus-staging
      Sonatype账号
      Sonatype密码
    
    
  • 修改pom.xml文件 增加许可协议、SCM信息、开发者信息 (最后附完整的pom.xml文件)

    
            
                The Apache Software License, Version 2.0
                http://www.apache.org/licenses/LICENSE-2.0.txt
                repo
            
        
        
            master
            [email protected]:Ants-double/mianhua.git
            scm:git:[email protected]:Ants-double/mianhua.git
            scm:git:[email protected]:Ants-double/mianhua.git
        
        
            
                ants-double
                [email protected]
                ants-double
            
        
  • 添加相关插件和仓库信息

    
                    
                        
                        
                            org.apache.maven.plugins
                            maven-source-plugin
                            2.2.1
                            
                                
                                    package
                                    
                                        jar-no-fork
                                    
                                
                            
                        
                        
                        
                            org.apache.maven.plugins
                            maven-javadoc-plugin
                            2.9.1
                            
                                ${chartset.UTF8}
                                true
                                ${chartset.UTF8}
                                ${chartset.UTF8}
                            
                            
                                
                                    attach-javadocs
                                    package
                                    
                                        jar
                                    
                                    
                                        -Xdoclint:none
                                    
                                
                            
                        
                        
                        
                            org.apache.maven.plugins
                            maven-gpg-plugin
                            1.5
                            
                                
                                    verify
                                    
                                        sign
                                    
                                
                            
                        
                        
                        
                            org.apache.maven.plugins
                            maven-compiler-plugin
                            3.0
                            
                                1.8
                                1.8
                                true
                                true
                                UTF-8
                                false
                            
                        
                        
                        
                            org.apache.maven.plugins
                            maven-release-plugin
                            2.5.1
                        
                    
                
                
                    
                        sonatype-nexus-snapshots
                        Sonatype Nexus Snapshots
                        https://oss.sonatype.org/content/repositories/snapshots/
                    
                    
                        sonatype-nexus-staging
                        Nexus Release Repository
                        https://oss.sonatype.org/service/local/staging/deploy/maven2/
                    
                

打包发布

  • 使用 命令,一键打包。

    `mvn clean deploy -P ` 
  • 打包过程中会要求输入gpg密钥的Passphase信息,输入即可

从零开始把项目发布到maven仓库中心_第2张图片

  • 然后到https://oss.sonatype.org/#stagingRepositories 查看,看到如下信息

    从零开始把项目发布到maven仓库中心_第3张图片

  • 然后去账号下面去回复评论,大概意思是我弄完了,你处理一下吧

    从零开始把项目发布到maven仓库中心_第4张图片

  • 最后在 nexus repository manager中staging repositories选中最新发布的项目,然后执行

    open -> closed
    closed->release
    执行完可以在activity中查看状态以角错误的原因
  • 最后按官网上说的过一会,maven Center可以更久一点就能查到了。

    https://search.maven.org/
    
    https://mvnrepository.com/
  • 附图

    从零开始把项目发布到maven仓库中心_第5张图片

完整的pom.xml



    4.0.0

    com.github.ants-double
    mainhua
    1.0-RELEASE

    mainhua
    https://github.com/Ants-double/mianhua
    常用工具集成

    
        
        1.8

        UTF-8
        UTF-8
        UTF-8
        UTF-8
        
        1.2.56
        1.18.8
        4.12

    

    
        
            
                com.alibaba
                fastjson
                ${project.fastjson.version}
            
            
                org.projectlombok
                lombok
                ${lombok.version}
            
            
                junit
                junit
                ${project.test.version}
                test
            
        
    
    
        
            com.alibaba
            fastjson
        
        
            org.projectlombok
            lombok
        
        
            junit
            junit
        
    
    
        
            The Apache Software License, Version 2.0
            http://www.apache.org/licenses/LICENSE-2.0.txt
            repo
        
    
    
        master
        [email protected]:Ants-double/mianhua.git
        scm:git:[email protected]:Ants-double/mianhua.git
        scm:git:[email protected]:Ants-double/mianhua.git
    
    
        
            ants-double
            [email protected]
            ants-double
        
    
    
        
            Releases
            
                
                    
                    
                        org.apache.maven.plugins
                        maven-source-plugin
                        2.2.1
                        
                            
                                package
                                
                                    jar-no-fork
                                
                            
                        
                    
                    
                    
                        org.apache.maven.plugins
                        maven-javadoc-plugin
                        2.9.1
                        
                            ${chartset.UTF8}
                            true
                            ${chartset.UTF8}
                            ${chartset.UTF8}
                        
                        
                            
                                attach-javadocs
                                package
                                
                                    jar
                                
                                
                                    -Xdoclint:none
                                
                            
                        
                    
                    
                    
                        org.apache.maven.plugins
                        maven-gpg-plugin
                        1.5
                        
                            
                                verify
                                
                                    sign
                                
                            
                        
                    
                    
                    
                        org.apache.maven.plugins
                        maven-compiler-plugin
                        3.0
                        
                            1.8
                            1.8
                            true
                            true
                            UTF-8
                            false
                        
                    
                    
                    
                        org.apache.maven.plugins
                        maven-release-plugin
                        2.5.1
                    
                
            
            
                
                    sonatype-nexus-snapshots
                    Sonatype Nexus Snapshots
                    https://oss.sonatype.org/content/repositories/snapshots/
                
                
                    sonatype-nexus-staging
                    Nexus Release Repository
                    https://oss.sonatype.org/service/local/staging/deploy/maven2/
                
            

        
    

出现的问题

  1. java1.8javadoc严格验证

    解决是添加
     
                                        -Xdoclint:none
                                    
  2. 项目id不存在,解决是添加命名的项目id

你可能感兴趣的:(从零开始把项目发布到maven仓库中心)