准备sonatype账号
注册sonatype
sonatype官网:sonatype
建议使用GitHub账号注册,后面可以省很多事
生成token
记住生成的username和password
配置maven
setting.xml
- 自定义id。记住该id,后面配置pom.xml用
- 配置sonatype生成的token(username & password)
<?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">
<servers>
<server>
<id>sonatype-zhouguangyao</id>
<username>xxx</username>
<password>xxxxxxxxx</password>
</server>
</servers>
</settings>
配置项目pom
下列两项的id使用上一步配置的自定义id
- plugin -> central-publishing-maven-plugin配置publishingServerId
- distributionManagement -> snapshotRepository配置id
<?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>io.github.zhouguangyao</groupId>
<artifactId>spp</artifactId>
<version>${revision}</version>
<packaging>pom</packaging>
<name>spp</name>
<description>spp is a flow</description>
<url>https://github.com/zhouguangyao/SmartProxyPool</url>
<issueManagement>
<system>Github Issue</system>
<url>https://github.com/zhouguangyao/SmartProxyPool/issues</url>
</issueManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>https://github.com/zhouguangyao/SmartProxyPool.git</connection>
<url>https://github.com/zhouguangyao/SmartProxyPool</url>
</scm>
<developers>
<developer>
<id>zhouguangyao</id>
<name>zhouguangyao</name>
<email>zhouguangyao1288@gmail.com</email>
<url>https://github.com/zhouguangyao</url>
<roles>
<role>Project Manager</role>
<role>Developer</role>
</roles>
<timezone>+8</timezone>
</developer>
</developers>
<inceptionYear>2024</inceptionYear>
<modules>
<module>spp-common</module>
<module>spp-core</module>
<module>spp-spring-boot-starter</module>
<module>spp-test</module>
</modules>
<properties>
<revision>1.0.0</revision>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.boot.version>2.5.14</spring.boot.version>
<flatten-maven-plugin.version>1.3.0</flatten-maven-plugin.version>
<junit.version>4.13.2</junit.version>
<slf4j-api.version>1.7.36</slf4j-api.version>
<jsoup.version>1.15.1</jsoup.version>
<transmittable.version>2.11.4</transmittable.version>
<fastjson.version>1.2.83</fastjson.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- SpringBoot的依赖配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.github.zhouguangyao</groupId>
<artifactId>spp-common</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>io.github.zhouguangyao</groupId>
<artifactId>spp-core</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>io.github.zhouguangyao</groupId>
<artifactId>spp-spring-boot-starter</artifactId>
<version>${revision}</version>
</dependency>
<!--for test-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestEntries>
<Implementation-Version>${revision}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- 统一版本号管理 -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>${flatten-maven-plugin.version}</version>
<configuration>
<updatePomFile>true</updatePomFile>
<flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<!-- mvn clean deploy -P release -->
<!-- source ~/.bash_profile -->
<plugins>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<configuration>
<windowtitle>spp</windowtitle>
<doctitle>spp</doctitle>
<show>private</show>
<detectLinks>false</detectLinks>
<detectOfflineLinks>true</detectOfflineLinks>
<linksource>true</linksource>
<additionalparam>-Xdoclint:none</additionalparam>
<detectJavaApiLink>true</detectJavaApiLink>
<source>8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<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.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<!-- 这里的serverId是之前在settings.xml中配置的 -->
<publishingServerId>sonatype-zhouguangyao</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>sonatype-zhouguangyao</id>
<name>snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-zhouguangyao</id>
<name>releases</name>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>
配置GPG
安装
使用命令安装、或者进去官网下载安装:gpg官网
brew install gpg
生成公钥
记住生成的pub key
gpg --gen-key
上传公钥
上传pub key
gpg --keyserver keyserver.ubuntu.com --send-keys CD31FB29129E90B884B9F7C81A665DE0FBC8E6D4
把send改成recv,验证是否上传成功
gpg --keyserver keyserver.ubuntu.com --recv-keys CD31FB29129E90B884B9F7C81A665DE0FBC8E6D4
发布项目
上传sonatype
发布sonatype
发布成功后,状态变成PUBLISHED。就可以在其他项目引用了