欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

发布jar包到Maven*仓库

程序员文章站 2022-07-10 16:22:36
...

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

Project URL 和SCM url 可以填写自己github项目的地址 
Group ID 可以按自己需求填写,比如我填写的是com.ailikes

创建好以后 sonatype的工作人员审核处理,速度还是很快的,一般一个工作日以内,当Issue的Status变为RESOLVED后,就可以进行下一步操作了,否则,就等待
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
到了这里说明你已经能够去上传自己的jar包了 
3 配置maven Setting.xml文件 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
 
添加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.ailikes</groupId>
	<artifactId>common-util</artifactId>
	<version>1.1.0-RELEASE</version>
	<name>common-util</name>
	<packaging>jar</packaging>
	<description>工具类工程</description>
	<url>https://github.com/AilikesXu/common-util.git</url>
	<developers>
	    <developer>
	            <name>ailikes</name>
	            <id>ailikes</id>
	            <email>15600499930@163.com</email>
	            <roles>
	                <role>Developer</role>
	            </roles>
	            <timezone>+8</timezone>
	        </developer>
	</developers>
	<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/AilikesXu</url>
        <connection>https://github.com/AilikesXu/common-util.git</connection>
    </scm>

	<properties>
		<argLine>-Dfile.encoding=UTF-8</argLine>
		<project-description>工具类工程</project-description>
		<java-version>1.7</java-version>
		<org.aspectj-version>1.8.4</org.aspectj-version>
		<org.slf4j-version>1.7.9</org.slf4j-version>
		<!-- 不加下面这一行会报错 [WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent! 增加之后 Using 'UTF-8' encoding to copy filtered resources. -->
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<org.springframework-version>4.1.4.RELEASE</org.springframework-version>
		<jetty.version>8.1.16.v20140903</jetty.version>
	</properties>
	<dependencies>
		<!-- java bean 验证 -->
		<dependency>
			<groupId>javax.validation</groupId>
			<artifactId>validation-api</artifactId>
			<version>1.1.0.Final</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-validator</artifactId>
		  	<version>5.4.1.Final</version>
		  	<scope>provided</scope>
		</dependency>
	</dependencies>
	<build>
	    <plugins>
	     	<plugin>
	            <groupId>org.apache.maven.plugins</groupId>
	            <artifactId>maven-compiler-plugin</artifactId>
	            <version>3.3</version>
	            <configuration>
	                <!-- 指定source和target的jdk版本是1.7 -->
	                <source>1.7</source>
	                <target>1.7</target>
	            </configuration>
	        </plugin>
		    <!-- 源码插件 -->
	  		<plugin>
	  			<groupId>org.apache.maven.plugins</groupId>
	  			<artifactId>maven-source-plugin</artifactId>
	  			<version>2.2.1</version>
	  			<!-- 发布时自动将源码同时发布的配置 -->
	  			<executions>
			    	<execution>
			    		<id>attach-sources</id>
			     		<goals>
			       			<goal>jar</goal>
			      		</goals>
			     	</execution>
			    </executions>
	  		</plugin>
	    </plugins>
	</build>
	<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>sonatype</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                </snapshotRepository>
                <repository>
                    <id>sonatype</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 
查看版本: 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar

$ 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 上传密钥 
上传刚刚生成的秘钥 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
上传命令

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

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

7执行部署

mvn clean deploy -P release
  • 1

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

8 登录网站查看

地址:https://oss.sonatype.org 
用户名密码就是上面注册的。 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
查看自己的(你定义的版本号不能带SNAPSHOT要不然看不到) 
a)构件准备好之后,在命令行上传构建;

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

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

9 通知管理员

去网站https://issues.sonatype.org 登录通知你的管理然后等待 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
然后到这里就全部完成。剩下的就是等同步到*仓库

看看我自己随便发布的一个结果: 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
去*仓库查看https://search.maven.org(*仓库需要两个小时后) 
发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar

  • 发布jar包到Maven*仓库
            
    
    博客分类: 工具使用技术分享 maven*仓库jar
  • 大小: 17 KB
相关标签: maven *仓库 jar