最近开源了自己写的银联在线网关支付SDK,并尝试将其发布到中央仓库。仅以此篇博客记录整个过程。
注册Sonatype帐号
[gt href=’https://issues.sonatype.org/secure/Signup!default.jspa’]注册Sonatype帐号[/gt]
注册逻辑非常简单跟注册QQ号差不多,这里过程不表。
创建问题
问题表单请如实填写
项目选择:Community Support – Open Source Project Repository Hosting (OSSRH)
问题类型:New Project
概要:X-UnionPay
描述:X-UnionPay–中国银联在线网关支付接口第三方SDK,旨在屏蔽底层逻辑提供一套简单的API方便调用。
Group Id:com.github.xuchengen
Project URL:https://github.com/Xuchengen/X-UnionPay
SCM url:https://github.com/Xuchengen/X-UnionPay.git
其它可填可不填。问题的审核大概需要一天的时间,审核期间还需验证Github仓库地址。
如上图所示,第一条评论需要我们在github上创建一个仓库进行身份验证。看到第二条评论基本可以确认我们可以上传自己的Jar包到Sonatype仓库。
配置Maven Setting.xml
<?xml version="1.0"encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- 自己指定本地仓库路径 --> <localRepository>/Users/xuchengen/z_dev/apache/maven/repo</localRepository> <servers> <server> <id>to-central-maven</id> <username>Sonatype帐号</username> <password>Sonatype密码</password> </server> </servers> <mirrors> </mirrors> <profiles> <!-- 上传Jar包到中央库 --> <profile> <id>to-central-maven</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <gpg.executable>gpg</gpg.executable> <gpg.passphrase>GPG密码</gpg.passphrase> </properties> </profile> </profiles> </settings>
配置项目pom.xml
[gt href=’https://github.com/Xuchengen/X-UnionPay/blob/master/pom.xml’]X-UnionPay项目POM配置参考[/gt]
<?xml version="1.0" encoding="UTF-8"?> <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.xuchengen</groupId> <artifactId>X-UnionPay</artifactId> <version>1.0-SNAPSHOT</version> <name>X-UnionPay</name> <description>X-UnionPay——中国银联在线网关支付接口第三方SDK,旨在屏蔽底层逻辑提供一套简单的API方便调用。</description> <url>https://github.com/Xuchengen/X-UnionPay</url> <scm> <connection>scm:git:https://github.com/Xuchengen/X-UnionPay.git</connection> <developerConnection>scm:git:https://github.com/Xuchengen/X-UnionPay.git</developerConnection> <url>https://github.com/Xuchengen/X-UnionPay.git</url> </scm> <licenses> <license> <name>The Apache License, Version 2.0</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> </license> </licenses> <developers> <developer> <name>徐承恩</name> <email>xuchengen@gmail.com</email> <organization>github</organization> <organizationUrl>https://xuchengen.github.io/</organizationUrl> </developer> </developers> <properties> <jdk>1.7</jdk> <encoding>UTF-8</encoding> </properties> <dependencies> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.6.1</version> </dependency> </dependencies> <profiles> <profile> <id>to-central-maven</id> <build> <plugins> <!-- 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> </plugins> </build> <distributionManagement> <snapshotRepository> <id>to-central-maven</id> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </snapshotRepository> <repository> <id>to-central-maven</id> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url> </repository> </distributionManagement> </profile> </profiles> <build> <plugins> <!-- 编译插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>${jdk}</source> <target>${jdk}</target> <encoding>${encoding}</encoding> <skip>true</skip> </configuration> </plugin> <!-- 源码插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.1.0</version> <executions> <execution> <phase>compile</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> <!--自动发布Jar到Maven仓库--> <plugin> <groupId>org.sonatype.plugins</groupId> <artifactId>nexus-staging-maven-plugin</artifactId> <version>1.6.7</version> <extensions>true</extensions> <configuration> <serverId>to-central-maven</serverId> <nexusUrl>https://oss.sonatype.org/</nexusUrl> <autoReleaseAfterClose>true</autoReleaseAfterClose> </configuration> </plugin> <!-- 资源文件处理插件 --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.1.0</version> <configuration> <encoding>${encoding}</encoding> </configuration> </plugin> </plugins> </build> </project>
使用GPG
Mac系统安装gpg
brew install gpg
其它系统平台各自去探索。
生成key只需要填写姓名和邮箱即可其它保持默认。
gpg --gen-key
上传到服务器
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys CF21873A--上传到服务器 gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys CF21873A --查看是否上传整个
部署Jar包到中央仓库
执行maven命令
mvn clean deploy -P to-central-maven
不出意外的话大概两个小时就能同步你的jar包到中央仓库。
[gt href=’https://search.maven.org’]搜索你自己的Jar包是否已上传到仓库[/gt]