建议以官网说明为准,网上教程存在一定的时效性。
临窗旋墨
2021-12
我的pom文件
地址:https://issues.sonatype.org/projects
过程略
Issue Type 为New Project
过程略 按部就班填写即可
但是可能审核不通过,可能是group Id 填写问题,参见:Choosing your Coordinates - The Central Repository Documentation (sonatype.org)
可以使用托管平台的子域
Service Example groupId Link to the hosting service Documentation GitHub io.github.myusername https://pages.github.com/ GitLab io.gitlab.myusername https://about.gitlab.com/stages-devops-lifecycle/pages/ Gitee io.gitee.myusername https://gitee.com/help/articles/4136
比如使用Gitee,的则把groupId设置为io.gitee.myusername, 然后新建一个public的仓库名字为jira号的(注意大小写保持一致),用以验证此仓库属于本人。
待jira变成RESOLVED/已解决
参考官网★:Apache Maven - The Central Repository Documentation (sonatype.org)
<server>
<id>sonatype-nexus-snapshots</id>
<username>Sonatype账号</username>
<password>Sonatype密码</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>Sonatype账号</username>
<password>Sonatype密码</password>
</server>
参考官网★:Apache Maven - The Central Repository Documentation (sonatype.org)
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.gitee.xuqiudong</groupId>
<artifactId>parent</artifactId>
<version>1.0.1</version>
<packaging>pom</packaging>
<!-- 下列三项是需要的 -->
<name>springboot项目的父项目</name>
<description>springboot项目的父项目</description>
<url>https://gitee.com/xuqiudong/vic-environment</url>
<!-- 开源许可证声明 有很多不同的开源许可证 Apache Version2.0 表示别人可以直接商用你的开源项目而无任何版权问题 -->
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<!--开源地址 -->
<scm>
<connection>scm:git:ssh://git@gitee.com:xuqiudong/vic-environment.git</connection>
<developerConnection>scm:git:https://gitee.com/xuqiudong/vic-environment.git</developerConnection>
<url>https://gitee.com/xuqiudong/vic-environment</url>
<tag>HEAD</tag>
</scm>
<!-- Issue地址 -->
<issueManagement>
<system>git Issue</system>
<url>https://gitee.com/xuqiudong/vic-environment/issues</url>
</issueManagement>
<!-- 开发者信息 -->
<developers>
<developer>
<name>vic.xu</name>
<email>xuduochoua@163.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
<properties>
<!-- gpg可执行命令路径 -->
<!--
<gpg.executable>D:\tools\dev\GnuPG\bin\gpg</gpg.executable>
<gpg.passphrase>12345678</gpg.passphrase>
-->
<vic.boot.version>1.0.0</vic.boot.version>
<vic.group>io.gitee.xuqiudong</vic.group>
<java.version>1.8</java.version>
<project.encoding>UTF-8</project.encoding>
<spring.boot.version>2.1.7.RELEASE</spring.boot.version>
<javax.servlet>4.0.0</javax.servlet>
<shiro-spring.version>1.6.0</shiro-spring.version>
<jwt.auth0.version>3.8.1</jwt.auth0.version>
<mybatis.starter.version>2.0.1</mybatis.starter.version>
<pagehelper.starter.version>1.2.10</pagehelper.starter.version>
<odbc.version>21.1.0.0</odbc.version>
<!-- 插件版本 -->
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19</maven-surefire-plugin.version>
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
<maven-javadoc-plugin.version>2.9.1</maven-javadoc-plugin.version>
<mybatis-generator-maven-plugin.version>1.3.2</mybatis-generator-maven-plugin.version>
<!-- 此版本被spring-boot使用 -->
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<!-- 打包时把源码打到本地 -->
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<!-- copy resources -->
<maven-resources-plugin.version>3.1.0</maven-resources-plugin.version>
<!-- spring boot -->
<spring-boot-maven-plugin.version>2.4.0</spring-boot-maven-plugin.version>
<elasticsearch.version>7.7.1</elasticsearch.version>
</properties>
<!-- Manage dependent versions of all sub-projects -->
<dependencyManagement>
</dependencyManagement>
<!-- 打包到中央仓库的地址 -->
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 指定jdk和编码 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.encoding}</encoding>
</configuration>
</plugin>
<!-- 跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!--打包时 把源码打包到本地 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- copy resources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<!--打jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<inherited>true</inherited>
<executions>
<execution>
<id>bundle-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<maxmemory>1024</maxmemory>
<encoding>UTF-8</encoding>
<show>protected</show>
<notree>true</notree>
<!-- Avoid running into Java 8's very restrictive doclint issues -->
<failOnError>true</failOnError>
<!-- 防止文档不规范报错 -->
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<!-- 在此府项目中引入一些常用插件 -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- 上传的时候使用的配置和插件 -->
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<!-- 这里的id必须要和全局配置中的server一致 -->
<serverId>ossrh</serverId>
<!-- 这个地址,一定要和issue的评论中给出的地址一致! -->
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<!-- 如果希望发布后自动执行close和release操作,此处可以调整为true -->
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>${maven-release-plugin.version}</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<!-- <releaseProfiles>release</releaseProfiles> -->
<goals>deploy nexus-staging:release</goals>
<checkModificationExcludes>
<checkModificationExclude>pom.xml</checkModificationExclude>
<checkModificationExclude>**</checkModificationExclude>
</checkModificationExcludes>
</configuration>
</plugin>
<!-- 11. 生成签名,确定使用那个gpg秘钥 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<keyname>vic.xu</keyname>
<passphraseServerId>vic.xu</passphraseServerId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
下载地址 :https://www.gpg4win.org/get-gpg4win.html
生成秘钥: 手动新建即可,
使用
gpg --list-keys
命令查询配置好的公私钥信息
使用 gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys <公钥key>
将公钥信息发送到ubuntu.com服务器,后续推送maven仓库会做校验。
以下几个地址都可以试试
gpg —keyserver hkp://keyserver.ubuntu.com:11371 —send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver keyserver.ubuntu.com —send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver keys.openpgp.org —send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver pgp.mit.edu —send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
查看公钥是否发送成功:
以下几个地址都可以试试
gpg —keyserver hkp://pool.sks-keyservers.net —recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver hkp://keyserver.ubuntu.com:80 —recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver keyserver.ubuntu.com —recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver keys.openpgp.org —recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg —keyserver pgp.mit.edu —recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
>
>
gpg --keyserver hkp://pool.sks-keyservers.net:11371 --send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg --keyserver hkp://pool.sks-keyservers.net:11371 --recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg --keyserver hkp://keys.gnupg.net:11371 --send-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
gpg --keyserver hkp://keys.gnupg.net:11371 --recv-keys 2CEFDDED844F56AADB1B3B57222970C5E4026FA9
mvn clean deploy -P release -X
使用release
的proifile
打包我的pom文件
登陆到https://s01.oss.sonatype.org/ (jira里提供的仓库地址,网上的部分教程和它不一致) 可查询到上传的包
如果 <autoReleaseAfterClose>false</autoReleaseAfterClose> 则可以去手动发布一下,
不然就不需要。
注意看如下日志: 当上面的参数为true时:
[DEBUG] Repository was removed; stop watching it
[DEBUG] iogiteexuqiudong-1035 REMOVED仓库的工作台是是看不到的,但是可以在如下地址看到( 30分钟后)
1 groupId
: 需要证明是domain的拥有者,所有后面改成了gitee的子域io.gitee.xuqiudong
, 然后在gitee
上建立一个仓库,仓库名为jira
号,注意大小写, 我复制jira
号到gitee
新建的时候,就自动变成了小写,结果无法通过。
2 . 一般的问题, 在deploy的时候加上-X
参数,如果出现错误,按部就班解决就可以了。比如javadoc
、java-source
没有生成。还有就是可能公钥没有上传成功。
参考:
Apache Maven - The Central Repository Documentation (sonatype.org)
我把自己的java库发布到了maven中央仓库,从此可以像Jackson、Spring的jar一样使用它了_程序员欣宸的博客-CSDN博客_java库发布