sonatype申请账号
申请地址: https://issues.sonatype.org/secure/Signup!default.jspa
申请完账号之后,登录
点击上方create,
创建item,Project选择Community Support - Open Source Project Repository Hosting (OSSRH)
Issue Type选择New Project
Summary自己填写
Group Id、Project URL、SCM url 按照下面填写
创建 Issue 后,等待审核即可。一般会在一个工作日内审核完成。当Issue的Status变为RESOLVED 或 FIXED 后,即可进行下一步操作。
GPG密钥安装
Windows 系统,可以下载 Gpg4win 软件来生成密钥对。下载地址:https://www.gpg4win.org/download.html
mac可以使用brew安装:
brew install gpg
gpg 常用命令
查看是否安装成功
gpg --version
生成密钥对
gpg --gen-key
查看公钥
gpg --list-keys
将公钥发布到PGP密钥服务器
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 公钥ID
查询公钥是否发布成功
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys
创建秘钥并发布
- 运行命令
gpg --gen-key
生成密钥对,按照提示输入真实姓名,邮箱等。然后生成密钥时候,会让你输入两次密码,这个密码要记住,后续会用到。 - 运行命令
gpg --list-keys
,查看本地密钥。 - 运行命令
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 密钥ID
,将发布密钥至密钥服务器
pom.xml配置
下面我提供的是我之前上传时候的pom.xml,可以根据自己情况修改,不要全部复制进去(比如依赖是我自己的,别复制到你自己的项目里)。
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.github.FeiChaoyu</groupId>
<artifactId>mybatis-layui</artifactId>
<version>1.0.0</version>
<name>mybatis-layui</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<mapper.starter.version>2.1.5</mapper.starter.version>
<pagehelper.starter.version>1.2.10</pagehelper.starter.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.9</version>
</dependency>
<!--mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>${mapper.starter.version}</version>
</dependency>
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper.starter.version}</version>
<exclusions>
<exclusion>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-generator</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<!--发布到maven仓库-->
<distributionManagement>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!--这是自动发布的插件-->
<!--<plugin>-->
<!--<groupId>org.sonatype.plugins</groupId>-->
<!--<artifactId>nexus-staging-maven-plugin</artifactId>-->
<!--<version>1.6.3</version>-->
<!--<extensions>true</extensions>-->
<!--<configuration>-->
<!--<serverId>ossrh</serverId>-->
<!--<nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
<!--<autoReleaseAfterClose>true</autoReleaseAfterClose>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<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>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<!-- java8版本导致javadoc打包编译失败时候,添加-->
<configuration>
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<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>
<url>https://github.com/FeiChaoyu/mybatis-layui</url>
<connection>https://github.com/FeiChaoyu/mybatis-layui.git</connection>
<developerConnection>https://github.com/FeiChaoyu</developerConnection>
</scm>
<developers>
<developer>
<name>feichaoyu</name>
<email>979331856@qq.com</email>
<url>https://github.com/FeiChaoyu</url>
</developer>
</developers>
</project>
需要注意
<groupId>你的全限定包名(保持和你之前sonatype上填写的Group Id一致)</groupId>
<id>ossrh</id>
这个id是需要和你的maven本地配置里的保持一致,下面会讲到。
还有就是Java doc的问题,请按照我上面的配置来,网上有用另一个方法的,但我试过了不行,这里我就不列举了。
本地maven settings.xml配置
在此之前需要先在本地装maven,然后到conf文件下找到settings.xml文件
在里面对应的地方加上
<server>
<id>ossrh</id>
<username>你的sonatype账号</username>
<password>你的sonatype密码</password>
</server>
提交项目到OSS
打开IDEA的Maven插件,输入如下命令,用于修改版本号
mvn versions:set -DnewVersion=1.0.0
执行如下命令即可将依赖发布到中央仓库
mvn clean deploy -P release
当执行以上 Maven 命令时,会自动弹出一个对话框,需要输入上面提到的 Passphase,它就是刚才设置的 GPG 密钥库的密码。
等待一段时间后,就发布成功了。
发布完最好使用如下命令重置为SNAPSHOT版本
mvn versions:set -DnewVersion=1.0.1-SNAPHOST
在 OSS中发布
如果之前用了我上面给的pom.xml中配置的自动发布插件,那么就可以省略手动发布操作
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
正常手动操作
进入https://oss.sonatype.org并登陆,会在左侧有个staging Repositories点击进入,在右侧面板找到你的构件,状态应该是open,你要将其置为closed,点击上方的close按钮即可。然后没问题后你需要点击release按钮发布你的构件。
Issue中通知工作人员已经成功发布
等待工作人员的回复。
之前由于发布时候用的SNAPSHOT版本,所以没有成功,工作人员回复我
之后如果成功了,就会出现
等10分钟就可以引入依赖了
<dependency>
<groupId>com.github.FeiChaoyu</groupId>
<artifactId>my-demo</artifactId>
<version>1.0.0</version>
</dependency>
等2个小时就能在Maven仓库中搜到你的项目了
至此,整个提交流程结束!