栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

发布到maven center仓库

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

发布到maven center仓库

发布到maven center仓库 官方说明:

为了让Maven用户利用项目生成的构件,必须将它们部署到maven center repository。 许多开源项目希望允许使用Maven构建的项目用户透明地访问项目的构件。 为了实现这一点,项目应该将其构件部署到中央存储库。

简单来说就是将我们自己写好的文件上传到maven中央仓库,其他人想用就可以通过依赖的方式去引入。

需求:
  1. releases: only releases can be uploaded to the Central Repository, that means files that won’t change and that only depend on other files already released and available in the repository,(只能是正式包,并且上传的文件只能依赖于中央仓库里面含有的依赖)

  2. javadoc and sources for IDE lookup(提供Java文档和源代码,遵循Maven存储库格式),

    格式命名:artifactId-version-classifier.packaging

    例如:

    example-application-1.4.7-sources.jar

    example-application-1.4.7-javadoc.jar

  3. PGP signature(一种签名,具体啥的还得百度下才知道),

    所有部署的文件都需要使用GPG/PGP进行签名,每个文件都必须包含一个包含签名.asc文件。

    例如:

    example-application-1.4.7-sources.jar.asc

    example-application-1.4.7-javadoc.jar.asc

  4. minimum POM information: There are some requirements for the minimal information in the POMs that are in the Central Repository, see here(为了保证能用,对POM文件的一些要求),

    Sufficient metadata

    作为部署的一部分,必须使用 Apache Maven来定义和构建项目对象模型

    Correct Coordinates

    按照groupId,artifactId,version(必须为正式包)来确定该Jar包在maven中央仓库的位置

    例如:

    com.example.applications

    example-application

    1.4.7

    Project Name, Description and URL

    为了提高代码的可读性,必须提供名字,描述和URL

    这里是项目名称哦 一般用 p r o j e c t . g r o u p I d : {project.groupId}: project.groupId:{project.artifactId}

    项目的简单描述哦

    http://www.example.com/example-application

    License Information

    必须要有许可证,就像你去别人家住,没有别人的许可,肯定也是住不了的哈

    例如:

    ​ The Apache License, Version 2.0

    ​ http://www.apache.org/licenses/LICENSE-2.0.txt

    Developer Information

    必须提供一个开发人员信息,出问题了可以立马联系到

    例如:

    ​ Manfred Moser

    ​ manfred@sonatype.com

    ​ Sonatype

    ​ http://www.sonatype.com

    SCM Information

    必须接入版本控制系统,git,svn…

    例如接入Git

    scm:git:git://github.com/simpligility/ossrh-demo.git scm:git:ssh://github.com:simpligility/ossrh-demo.git http://github.com/simpligility/ossrh-demo/tree/master

    Fully configured example projects including metadata as well as dependencies and Maven build configuration are, for example, available at

    • https://github.com/simpligility/ossrh-demo/blob/master/pom.xml
    • https://bitbucket.org/simpligility/ossrh-pipeline-demo/src
  5. coordinates: Picking the appropriate coordinates for your project is important. See the guidelines here, particularly on groupId and domain ownership.(坐标,参考上面第4点的Correct Coordinates)

Publishing your artifacts to the Central Repository Approved Repository Hosting

必须使用官方认证的库

  • Apache Software Foundation (for all Apache projects)
  • see the full list
Other Projects

The easiest way to upload another project is to use the Open Source Software Repository Hosting (OSSRH), which is an approved repository provided by Sonatype for any OSS Project that want to get their artifacts into the Central Repository.

使用托管库上传,maven中央仓库每隔一段时间就去托管库更新

一个简单的例子
  1. pom.xml 中必须包括:name、description、url、licenses、developers、scm 等基本信息

    
        repository
        https://oss.sonatype.org/service/local/staging/deploy/maven2/
    
    
        ossrh
        https://oss.sonatype.org/content/repositories/snapshots
    


    
        disable-javadoc-doclint
        
            [1.8,)
        
        
        
            -Xdoclint:none
        
    
    
        release
        
            
                
                
                    org.sonatype.plugins
                    nexus-staging-maven-plugin
                    1.6.3
                    true
                    
                        ossrh
                        https://oss.sonatype.org/
                        true
                    
                

                
                    org.apache.maven.plugins
                    maven-release-plugin
                    2.3.2
                    
                        true
                        false
                        release
                        deploy
                    
                
                
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    3.0
                    
                        1.8
                        1.8
                    
                
                
                
                    org.apache.maven.plugins
                    maven-gpg-plugin
                    1.5
                    
                        
                            sign-artifacts
                            verify
                            
                                sign
                            
                        
                    
                
                
                
                    org.apache.maven.plugins
                    maven-source-plugin
                    2.2.1
                    
                        
                            attach-sources
                            
                                jar-no-fork
                            
                        
                    
                
                
                
                    org.apache.maven.plugins
                    maven-javadoc-plugin
                    2.10.4
                    
                        
                            attach-javadocs
                            package
                            
                                jar
                            
                            
                            
                                ${javadoc.opts}
                            
                        
                    
                
            
        
    



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

            

    https://gitee.com/ikcross/aim-cloud.git
    https://gitee.com/ikcross/aim-cloud.git
    https://gitee.com/ikcross/aim-cloud

          

    
        yanyiqiu
        yanyiqiu@meizu.com
        自己的域名
    

  1. magen的setting.xml配置

需要添加sonatype的身份认证,就是你一开始申请账号时候的用户名和密码。id要和pom.xml中distributionManagement 中的snapshotRepository和repository保持一致。

      
      id  
      yourname
      yourpass!
      
  1. 执行下面命令

    mvn clean install deploy -P release -Dgpg.passphrase=生成PGP秘钥时候你的密码
    

​ 可以通过gpg秘钥安装来发布到PGP的秘钥服务器

构建完就可以上sonatype这个网站进行发布啦

参考:

https://zhuanlan.zhihu.com/p/41650855

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/532271.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号