1、注册一个https://issues.sonatype.org/的账号
密码很复杂,建议拿个小本本记下来
进去之后点击创建
点击新建一个项目,有时候直接进去就可以创建,注意问题类型要为new project
概要和描述正常写就行,groupid
为域名,我是在github上建了个仓库,因此填了github的groupid。
project url
就填github地址,scm url
就填github地址后加.git
点击创建就可以了,等待回复,我等了十来分钟。
2、安装并配置GPG
下载Gpg4win 3.1.5
秘钥生成工具 下载跳转
一个傻瓜式的秘钥生成工具,正常生成就可以,记住passphrase
,生成后点击发布:
3、配置maven的setting.xml
<server>
<id>ossrh</id>
<username>sonatype账号</username>
<password>sonatype密码</password>
</server>
4、配置项目pom.xml
文件
distributionManagement
节和maven-compiler-plugin
节的配置信息根据自己的实际情况做修改。,
<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:https://github.com/zhao458114067/repository-util.git</connection>
<url>git:https://github.com/zhao458114067/repository-util</url>
</scm>
<developers>
<developer>
<name>zx</name>
<email>zhaoxu1@supcon.com</email>
<roles>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
<profiles>
<profile>
<id>release</id>
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.sample</include>
</includes>
</resource>
</resources>
<plugins>
<!-- source包 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 生成doc文档 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<distributionManagement>
<repository>
<id>ossrh</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>ossrh</id>
<name>Nexus Release Repository</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
5、发布
mvn clean deploy -Darguments=“gpg.passphrase=私钥值”,私钥值为gpg程序生成的passphrase
“密匙设置”值
注意groupid
与创建问题时的groupid保持一致
第一次部署需要设置distributionManagement
为以下内容
<distributionManagement>
<repository>
<id>ossrh</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2</url>
</repository>
<snapshotRepository>
<id>ossrh</id>
<name>Nexus Release Repository</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots//</url>
</snapshotRepository>
</distributionManagement>
version需要设置如下:
<version>1.0-SNAPSHOP</version>
上传成功如下:
搜索即可以看到自己的项目
**https://repo1.maven.org/maven2/
https://mvnrepository.com/
也可以查,但是同步比较慢大概需要一两个小时才能查到