前段时间使用Gitee仓库搭建了一个Maven私有仓库,将一些开源包放到上面去,感受使用起来仍是不太方便,最近就折腾将这些包提交到Maven的中央仓库中。项目第一次提交Maven仍是挺麻烦的,因此写个文章Mark一下。java
注册一个sonatype.org账号,登录并提交一个issue,没错,就是提交一个issue,具体可参考以下:
git
其中:spring
New Project
;settings.xml
在Maven的settings.xml
文件中增长<server>
配置,配置你sonatype的帐号密码,参考以下:apache
<servers> <server> <id>sonatype-nexus-snapshots</id> <username>demo</username> <password>******</password> </server> <server> <id>sonatype-nexus-staging</id> <username>demo</username> <password>******</password> </server> </servers>
pom.xml
license
、scm
、developer
信息。<licenses> <license> <name>The Apache Software License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> </license> </licenses> <scm> <tag>master</tag> <url>git@gitee.com:centy/xxl-job-spring-boot-starter.git</url> <connection>scm:git:git@gitee.com:centy/xxl-job-spring-boot-starter.git</connection> <developerConnection>scm:git:git@gitee.com:centy/xxl-job-spring-boot-starter.git</developerConnection> </scm> <developers> <developer> <name>centychen</name> <email>292462859@qq.com</email> </developer> </developers>
profile
配置,注意:distributionManagement.snapshotRepository
和distributionManagement.repository
的id需与settings.xml
中对应的server记录ID一致;distributionManagement的url根据官方反馈的url修改。<profiles> <profile> <id>release</id> <build> <plugins> <!-- Source --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.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>3.1.0</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.5</version> <executions> <execution> <phase>verify</phase> <goals> <goal>sign</goal> </goals> </execution> </executions> </plugin> <!--Compiler--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> <configuration> <source>1.8</source> <target>1.8</target> <fork>true</fork> <verbose>true</verbose> <encoding>UTF-8</encoding> <showWarnings>false</showWarnings> </configuration> </plugin> <!--Release--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.3</version> </plugin> </plugins> </build> <distributionManagement> <snapshotRepository> <id>sonatype-nexus-snapshots</id> <name>Sonatype Nexus Snapshots</name> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> </snapshotRepository> <repository> <id>sonatype-nexus-staging</id> <name>Nexus Release Repository</name> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> </repository> </distributionManagement> </profile> </profiles>
brew install gpg
执行安装;gpg --gen-key
生成公私钥,按照提示信息一步步操做,须要记住加密使用的Passphrase
,下面步骤需使用;gpg --list-keys
查看公钥ID,经过一下命令上传:gpg --send-keys [公钥ID] --keyserver hkp://keyserver.ubuntu.com:11371
***-SNAPSHOT
格式,如1.0.0-SNAPSHOT
。mvn clean deploy -P release -Dmaven.test.skip=true
Deploy的时候会弹出一个输入Passphrase
的页面,输入刚才生成pgp公私钥使用的密码。 ubuntu
构建完成后,在https://oss.sonatype.org/content/repositories/snapshots中应该能够找到刚刚提交的snapshot版本。服务器
***-RELEASE
或者无后缀格式,如1.0.0-RELEASE
、1.0.0
。mvn clean deploy -P release -Dmaven.test.skip=true
Deploy的时候会弹出一个输入Passphrase
的页面,输入刚才生成pgp公私钥使用的密码。 app
登录https://oss.sonatype.org/,点击左侧Staging Repositories
,输入你的group id查找,可看到deploy记录: maven
选中Deploy记录点击Close
并Confirm
,刷新后会发现记录状态已经变成Closed
。spring-boot
再选中记录点击Release
并Confirm
完成发布,发布完成后须要等待中央仓库同步,我是等了1个多小时才能在中央仓库搜索出来。ui
使用mvn clean deploy
命令构建时,可能会报gpg: signing failed: Inappropriate ioctl for device
,是由于没法弹出Passphrase页面,须要在系统环境变量中增长export GPG_TTY=$(tty)
。
若是Deploy的时候报 Access denied to staging repository...
等错误,恭喜你,你的账号权限有问题,须要再提一个issue处理该问题,可参考我提的issue。
应该是执行close操做的数据校验有问题,好比pom.xml信息缺失等,我第一次提交的时候就没有在pom.xml中配置project name,校验就没有经过。留意页面下方Activity中的错误信息便可。