如何将自己的jar包上传到Maven中央仓库
原创
©著作权归作者所有:来自51CTO博客作者简单美好的原创作品,请联系作者获取转载授权,否则将追究法律责任
什么是Maven中央仓库
Maven中央仓库
我们平常使用的mvnrepository 和阿里云仓库和中央仓库什么关系呢?
以Maven中央仓库为准,定期做同步工作。因此我们将jar发布到中央仓库,过几天就会在阿里云或者mvmrepository中看到了。
如何上传
Sonatype JIRA账号注册:https://issues.sonatype.org/secure/Signup!default.jspa
官方教程地址:https://central.sonatype.org/pages/ossrh-guide.html
官方仓库:https://search.maven.org
oss:https://oss.sonatype.org/#profile;Summary
如果有能力,不要再看博客浪费自己的时间了。包括我的,尽可能观看官方文档。
注意事项
以下注意事项为Windows中,其他可能也适用,但不保证哈。
gpg安装地址:https://gpg4win.org/download.html
为了保证jar上传到中央仓库过程中不被修改,需要一种安全策略,就使用了gpg
gpg可以通过可视化界面上传证书到maven
上传完毕后需要查看,然后执行相关操作
必须在本地安装gpg,推荐可视化的
相关配置
build and distrutionManagement
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
<!-- 必须配置 source-->
<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-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 必须配置 javadoc-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.3</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 必须配置 sonatype-->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<!-- 等于上面Settings中server的id值。-->
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- 必须配置 GPG-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id> <!-- 等于上面Settings.xml中server的id值。-->
<name>oss Snapshots Repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id> <!-- 等于上面Settings.xml中server的id值。-->
<name>oss Staging Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
一般需要增加描述和licenses
<name>kingosoft-code-break-util</name>
<description>青果教务系统验证码识别</description>
<url>https://github.com/BoomManPro/kingosoft-code-break-util</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>BoomManPro</name>
<email>l.o.v.e_y.o.u_3344@qq.com</email>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/simpligility/ossrh-demo.git</connection>
<developerConnection>scm:git:ssh://github.com:simpligility/ossrh-demo.git</developerConnection>
<url>https://github.com/BoomManPro/kingosoft-code-break-util</url>
</scm>
参考可见:pom.xml