zoukankan      html  css  js  c++  java
  • 发布jar包到Maven中央仓库

    平时自己开发的工具类或者其他的框架的jar包一般都是放在本地。或者把代码上传到github让别人去下载然后自己打包。今天就说说如何把自己的jar包发布到Maven的中央仓库。让其他使用你的jar包的直接去中央仓库下载。如果你用的是阿里云的maven中央仓库。同样阿里云的中央仓库也会同步你的jar包。
    1 注册JIRA账号
    注册地址:https://issues.sonatype.org/secure/Dashboard.jspa
    2 创建 issue

    这些都是要填写的!Project URL 和SCM url 可以填写自己github项目的地址
    Group ID 可以按自己需求填写,比如我填写的是com.github.mxsm
    创建好以后 sonatype的工作人员审核处理,速度还是很快的,一般一个工作日以内,当Issue的Status变为RESOLVED后,就可以进行下一步操作了,否则,就等待… (国内最好你在晚上干这个事情国外刚好上班)
    这里写图片描述
    到了这里说明你已经能够去上传自己的jar包了
    3 配置maven Setting.xml文件
    这里写图片描述

    添加Server节点

    <server>
                <id>自行替换</id>
                <username>替换成自己的JIRA账号</username>
                <password>替换成自己的JIRA账号密码</password>
            </server>

    4 创建maven工程
    设置pom.xml文件

    <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.github.mxsm</groupId>
      <artifactId>dubbotest</artifactId>
      <version>1.0</version>
      <packaging>jar</packaging>
    
      <name>dubbotest</name>
      <url>https://github.com/mxsm</url>
      <description>dubbotest com.github.mxsm jar</description>    
      
      <licenses>
            <license>
                <name>Apache 2</name>
                <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
                <distribution>repo</distribution>
                <comments>A business-friendly OSS license</comments>
            </license>
        </licenses>
      
        <scm>
            <url>https://github.com/mxsm</url>
            <connection>https://github.com/mxsm/taokeeper.git</connection>
        </scm>
      
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>
    
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.3.10.RELEASE</version>
        </dependency>
        
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
        </dependency>
        
      </dependencies>
      
      <developers>
          <developer>
                <name>ljbmxsm</name>
                <id>ljbmxsm</id>
                <email>ljbmxsm@gmail.com</email>
                <roles>
                    <role>Developer</role>
                </roles>
                <timezone>+8</timezone>
            </developer>
      </developers>
          <profiles>
            <profile>
                <id>release</id> <!-- 部署要用到 -->
                <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.9.1</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.6</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>
            </profile>
        </profiles>
    </project>

    必须要的:name url description licenses scm

    <distributionManagement>
                    <snapshotRepository>
                        <id>oss</id><!-- settings.xml中server节点的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>

    5 windows环境安装gpg4win
    下载地址:https://www.gpg4win.org/download.html
    查看版本:

    
    

    $ gpg --gen-key
    gpg (GnuPG) 1.4.19; Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    Please select what kind of key you want:
       (1) RSA and RSA (default)
       (2) DSA and Elgamal
       (3) DSA (sign only)
       (4) RSA (sign only)
    Your selection?
    RSA keys may be between 1024 and 4096 bits long.
    What keysize do you want? (2048)
    Requested keysize is 2048 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)
    Key does not expire at all
    Is this correct? (y/N) Y
    
    You need a user ID to identify your key; the software constructs the user ID
    from the Real Name, Comment and Email Address in this form:
        "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
    
    Real name: ljbmxsm
    Email address: ljbmxsm@gmail.com
    Comment: flink-elasticsearch-connector
    You selected this USER-ID:
        "iteblog (flink-elasticsearch-connector) <wyphao.2007@163.com>"
    
    Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
    You need a Passphrase to protect your secret key.
    
    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: /c/Users/iteblog/.gnupg/trustdb.gpg: trustdb created
    gpg: key B15C5AA3 marked as ultimately trusted
    public and secret key created and signed.

    设置名字+邮箱,其他可以使用默认值,记住输入的passphrase,后面部署会用到
    6 上传密钥
    上传刚刚生成的秘钥
    这里写图片描述
    上传命令

    gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys CF21873A--上传到服务器
    gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys  CF21873A --查看是否上传整个

    主要:keyserver.ubuntu.com:11371 现在这个是可用的,之前网上的pool.sks-keyservers.net 反正我上传成功但是在后面验证的时候不是用的这个地址。
    ##7执行部署

    mvn clean deploy -P release

    后面的release参数是 <id>release</id> <!-- 部署要用到 --> 这个

    8 登录网站查看

    地址:https://oss.sonatype.org
    用户名密码就是上面注册的。

    查看自己的(你定义的版本号不能带SNAPSHOT要不然看不到)
    a)构件准备好之后,在命令行上传构建;

    b)在https://oss.sonatype.org/ “close”并“release”构件;

    c)等待同步好(大约2小时多)之后,就可以使用了

    9 通知管理员

    去网站https://issues.sonatype.org 登录通知你的管理然后等待
    这里写图片描述
    然后到这里就全部完成。剩下的就是等同步到中央仓库

    看看我自己随便发布的一个结果:
    这里写图片描述
    去中央仓库查看https://search.maven.org(中央仓库需要两个小时后)
    这里写图片描述

    查看自己的(你定义的版本号不能带SNAPSHOT要不然看不到)
    a)构件准备好之后,在命令行上传构建;

    b)在https://oss.sonatype.org/ “close”并“release”构件;

    c)等待同步好(大约2小时多)之后,就可以使用了

    9 通知管理员

    去网站https://issues.sonatype.org 登录通知你的管理然后等待
    这里写图片描述
    然后到这里就全部完成。剩下的就是等同步到中央仓库

    看看我自己随便发布的一个结果:
    这里写图片描述
    去中央仓库查看https://search.maven.org(中央仓库需要两个小时后)
    这里写图片描述

  • 相关阅读:
    awk如何替换一个字符串的第n个字符?
    开启停止wifi热点bat脚本
    启停无线网卡bat脚本
    批量查找ip地址归属地脚本
    测试域名ping延迟脚本
    多线程FTP下载日志脚本
    社交网站好友储存设计和实现(PHP+MySQL)
    Python强化训练笔记(二)——元组元素的命名
    Python强化训练笔记(一)——在列表,字典,集合中筛选数据
    Android Studio安装配置
  • 原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/13833353.html
Copyright © 2011-2022 走看看