上传maven中央仓库
上传maven中央仓库
在官方的文档中提到:
从 2024 年 3 月 12 日起,所有注册都将通过中央门户网站进行。有关传统注册的信息,请参阅相关文档。有关在门户网站早期访问期间通过传统的 OSSRH 发布方式进行发布的支持,请参阅以下部分。
大致操作步骤如下:
- 配置sonatype账号
- 注册账号
- 创建命名空间
- 获取 User Token
- 配置GPG
- 安装GPG
- 生成密钥
- 发送公钥
- 配置pom文件
- 发布项目
配置sonatype账号
注册账号
进入官网:https://central.sonatype.com/
点击右上角 Sign In,然后点击下面的 Sign up,填写账号、密码、邮箱,注册自己的账号。
创建命名空间
登录自己的账号之后,进入网站主页,点击右上角的 Publish 按钮,进入 Namespace 模块,然后点击 Add Namespace 按钮。
命名空间具有唯一性,必须是属于你且没有被其他人使用的,这里我使用了我的域名 top.hjcwzx 作为命名空间。
命名空间对应着 Maven 依赖的 groupId。
如果你直接通过GitHub注册的sonatype,应该会直接给你授权你账号的github命名空间。
如果你的命名空间注册失败,那可能是被其他人注册了,但官网上没看到写解决方案,如果你遇到了这种情况,可以网上搜一下解决方案。
点击提交后,需要验证命名空间。
个人域名是通过 TXT 记录验证的,需要在域名的 DNS 解析中添加一条 TXT 记录。
如果你没有域名,也可以使用 GitHub 或者 GitLab、Gitee 的用户名作为命名空间:
- GitHub io.github.username
- GitLab io.gitlab.username
- Gitee io.gitee.username
比如我使用 GitHub 来作为我的命名空间,我的 GitHub 用户名是hjc1732,那么命名空间就写 io.github.hjc1732
。
GitHub的验证方式是通过让你新建仓库来验证的,你只需要根据它指定的名称新建一个仓库就好了。
配置好验证所需要的条件后,点击 confirm
按钮,然后等待验证通过,一般几秒钟就可以了。
获取 User Token
点击右上角的view account -> 点击Generate User Token -> 点击ok。
然后会得到一个这样的数据:
<server>
<id>${server}</id>
<username>xxxxxxx</username>
<password>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</password>
</server>
这个是你上传jar包时,用来验证你的身份的,不要泄露给别人。
把这段数据复制下来,粘贴到 Maven 的 setting.xml 里面,把 ${server}
改成你自定义的内容,这个自定义的内容要记下来,后面还要用到的,这里我改成了 sonatype-hjc
。
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
|
| 2. Global Level. This settings.xml file provides configuration for all Maven
| users on a machine (assuming they're all using the same Maven
| installation). It's normally provided in
| ${maven.conf}/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -gs /path/to/global/settings.xml
|
| The sections in this sample file are intended to give you a running start at
| getting the most out of your Maven installation. Where appropriate, the default
| values (values used when the setting is not specified) are provided.
|
|-->
<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
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository-->
<localRepository>D:\Devapp\Maven\repository</localRepository>
<!-- interactiveMode
| This will determine whether maven prompts you when it needs input. If set to false,
| maven will use a sensible default value, perhaps based on some other setting, for
| the parameter in question.
|
| Default: true
<interactiveMode>true</interactiveMode>
-->
<!-- offline
| Determines whether maven should attempt to connect to the network when executing a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false
<offline>false</offline>
-->
<!-- pluginGroups
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
|-->
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<!-- proxies
| This is a list of proxies which can be used on this machine to connect to the network.
| Unless otherwise specified (by system property or command-line switch), the first proxy
| specification in this list marked as active will be used.
|-->
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
<!-- servers
| This is a list of authentication profiles, keyed by the server-id used within the system.
| Authentication profiles can be used whenever maven must make a connection to a remote server.
|-->
<servers>
<server>
<id>sonatype-hjc</id>
<username>******</username>
<password>******</password>
</server>
<!-- server
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
-->
<!-- Another sample, using keys to authenticate.
<server>
<id>siteServer</id>
<privateKey>/path/to/private/key</privateKey>
<passphrase>optional; leave empty if not used.</passphrase>
</server>
-->
</servers>
<!-- mirrors
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
|
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
| However, this repository may have problems with heavy traffic at times, so people have mirrored
| it to several places.
|
| That repository definition will have a unique id, so we can create a mirror reference for that
| repository, to be used as an alternate download site. The mirror site will be the preferred
| server for that repository.
|-->
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<!-- profiles
| This is a list of profiles which can be activated in a variety of ways, and which can modify
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
| specific paths and repository locations which allow the build to work in the local environment.
|
| For example, if you have an integration testing plugin - like cactus - that needs to know where
| your Tomcat instance is installed, you can provide a variable here such that the variable is
| dereferenced during the build process to configure the cactus plugin.
|
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
| section of this document (settings.xml) - will be discussed later. Another way essentially
| relies on the detection of a system property, either matching a particular value for the property,
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
| Finally, the list of active profiles can be specified directly from the command line.
|
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
| repositories, plugin repositories, and free-form properties to be used as configuration
| variables for plugins in the POM.
|
|-->
<profiles>
<!-- profile
| Specifies a set of introductions to the build process, to be activated using one or more of the
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
| or the command line, profiles have to have an ID that is unique.
|
| An encouraged best practice for profile identification is to use a consistent naming convention
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
| This will make it more intuitive to understand what the set of introduced profiles is attempting
| to accomplish, particularly when you only have a list of profile id's for debug.
|
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
<profile>
<id>jdk-1.4</id>
<activation>
<jdk>1.4</jdk>
</activation>
<repositories>
<repository>
<id>jdk14</id>
<name>Repository for JDK 1.4 builds</name>
<url>http://www.myhost.com/maven/jdk14</url>
<layout>default</layout>
<snapshotPolicy>always</snapshotPolicy>
</repository>
</repositories>
</profile>
-->
<!--
| Here is another profile, activated by the system property 'target-env' with a value of 'dev',
| which provides a specific path to the Tomcat instance. To use this, your plugin configuration
| might hypothetically look like:
|
| ...
| <plugin>
| <groupId>org.myco.myplugins</groupId>
| <artifactId>myplugin</artifactId>
|
| <configuration>
| <tomcatLocation>${tomcatPath}</tomcatLocation>
| </configuration>
| </plugin>
| ...
|
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
| anything, you could just leave off the <value/> inside the activation-property.
|
<profile>
<id>env-dev</id>
<activation>
<property>
<name>target-env</name>
<value>dev</value>
</property>
</activation>
<properties>
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
</properties>
</profile>
-->
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
<!-- activeProfiles
| List of profiles that are active for all builds.
|
<activeProfiles>
<activeProfile>alwaysActiveProfile</activeProfile>
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
</activeProfiles>
-->
<activeProfiles>
<activeProfile>jdk-1.8</activeProfile>
</activeProfiles>
</settings>
配置GPG
发布到Maven仓库中的所有文件都要使用GPG签名,以保障完整性。因此,我们需要在本地安装并配置GPG。
安装GPG
进入官网:https://gnupg.org/download/index.html
下载自己需要的版本,windows的同学跟我的操作一样进行下载就好了:
下载完直接安装,无脑下一步就好了,除了最后的文件路径要修改一下,前面的都不用管。
组件选择默认的就可以了,咱也没那么多需求,能用就行😋。
安装完之后,windows版会自动帮我们添加系统环境变量,我们随便找个地方打开cmd窗口就可以使用了(uTools的cmd除外)。
如果用不了的话,找到GPG的安装目录,目录的旁边还有一个 GnuPG 文件夹,然后进入 GnuPG 文件夹下的bin目录,在这些目录下打开 cmd 窗口。
可以使用 gpg --version
来验证是否安装成功。
生成密钥
命令行输入gpg --gen-key
然后根据提示依次输入 Real name 和 Email address,注意这里的 Real name 必须填你在 sonatype 创建的 namespace。
如果你的namespace是用的自己的域名,那 name 就填域名,如果namespace是github的账号,那 name 就填GitHub账号名称,比如:
namespace:top.hjcwzx
Real name:top.hjcwzx
namespace:io.github.hjc1723
Real name:hjc1723
然后会弹出窗口让你输入密钥,这个密钥也需要记住,你每次上传的时候都会让你输入密码的。
接着我们再回到刚刚的cmd界面,注意最下面的信息,里面有一个公钥:
C:\project_software\gpg\GnuPG\bin>gpg --list-keys
[keyboxd]
---------
pub ed25519 2024-07-11 [SC] [expires: 2027-07-11]
3F09E6E8D507BD450210082E0CDDDCB54FEF09E4
uid [ultimate] top.hjcwzx <1732648485@qq.com>
sub cv25519 2024-07-11 [E] [expires: 2027-07-11]
中间 D8F859ACBB78E66AB97AB672766C17B3A2AA7414
这段就是你的公钥,私钥它已经作为文件保存到你的电脑里了。
如果你不小心把cmd窗口关掉了,也可以通过 gpg --list-keys
命令来重新查看你以前生成过的密钥信息。
发送公钥
秘钥对生成好后,需要把公钥上传到公共服务器供sonatype验证:
gpg --keyserver keyserver.ubuntu.com --send-keys 3F09E6E8D507BD450210082E0CDDDCB54FEF09E4
中央服务器当前支持的 GPG 密钥服务器有:
keyserver.ubuntu.com
keys.openpgp.org
pgp.mit.edu
发送完需要验证是否成功:
gpg --keyserver keyserver.ubuntu.com --recv-keys 3F09E6E8D507BD450210082E0CDDDCB54FEF09E4
如果发送失败,可以多试几次,也可以换另外两个网址试试。
参考我的发送和验证过程:
到这里 GPG 就配置完毕了!
配置pom文件(最麻烦)
这个部分略微有点麻烦,我直接放上我的完整pom文件给你参考,你再根据我在后面写的说明进行修改和调整就可以了。
我的配置成功的
<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>top.hjcwzx</groupId>
<artifactId>dynamic-thread-pool-spring-boot-starter</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>dynamic-thread-pool-spring-boot-starter</name>
<url>https://gitee.com/dynamic-thread-pool/dynamic-thread-pool</url>
<description>
dynamic-thread-pool-springboot-starter
</description>
<developers>
<developer>
<id>hjc</id>
<name>小胡</name>
<roles>
<role>Project Manager</role>
<role>Developer</role>
</roles>
<email>hjc@xxx.com</email>
<url>https://github.com/hjc1732</url>
</developer>
</developers>
<issueManagement>
<system>Github</system>
<url>https://github.com/hjc1732/dynamic-thread-pool-spring-boot-starter/issues</url>
</issueManagement>
<inceptionYear>2024</inceptionYear>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/hjc1732/dynamic-thread-pool-spring-boot-starter.git</connection>
<developerConnection>scm:git:git@github.com:hjc1732/dynamic-thread-pool-spring-boot-starter.git</developerConnection>
<url>https://github.com/hjc1732/dynamic-thread-pool-spring-boot-starter</url>
<tag>HEAD</tag>
</scm>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/>
</parent>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<dynamic-version>1.0</dynamic-version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.3-jre</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.49</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>3.26.0</version>
</dependency>
</dependencies>
<build>
<finalName>dynamic-thread-pool-spring-boot-starter</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/**</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</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-hjc</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
<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>
<configuration>
<!-- 改成你自己的路径 -->
<executable>C:\project_software\gpg\GnuPG\bin\gpg.exe</executable>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
他人配置成功的1 (profiles的方式不晓得为啥deploy的时候不好用)
profiles的方式放插件不晓得为啥deploy的时候不好用,之后把插件放在build中了
<?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>cn.sticki</groupId>
<artifactId>spel-validator</artifactId>
<version>0.0.2-beta</version>
<packaging>jar</packaging>
<name>Spel Validator</name>
<url>https://github.com/stick-i/spel-validator</url>
<description>
Bean Validator With Spring Expression Language
</description>
<developers>
<developer>
<id>sticki</id>
<name>阿杆</name>
<roles>
<role>Project Manager</role>
<role>Developer</role>
</roles>
<email>sticki@xxx.com</email>
<url>https://github.com/stick-i</url>
</developer>
</developers>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/stick-i/spel-validator/issues</url>
</issueManagement>
<inceptionYear>2024</inceptionYear>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/stick-i/spel-validator.git</connection>
<developerConnection>scm:git:git@github.com:stick-i/spel-validator.git</developerConnection>
<url>https://github.com/stick-i/spel-validator</url>
<tag>HEAD</tag>
</scm>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.2.5.Final</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- Source -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.1.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<excludeResources>true</excludeResources>
<useDefaultExcludes>true</useDefaultExcludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>attach-javadocs</id>
<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>
<configuration>
<!-- 改成你自己的路径 -->
<executable>E:\_Gpg4win\GnuPG\bin\gpg.exe</executable>
</configuration>
<executions>
<execution>
<phase>verify</phase>
<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-sticki</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
他人配置成功的2 (可借鉴)
<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.gitee.wangfugui-ma</groupId>
<artifactId>aliyun-oss-spring-boot-starter</artifactId>
<version>0.0.1</version>
<name>aliyun-oss-spring-boot-starter</name>
<description>aliyun-oss-spring-boot-starter</description>
<url>https://gitee.com/wangfugui-ma/aliyun-oss-spring-boot-starter</url>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<id>masiyi</id>
<name>masiyi</name>
<email>masiyi163163@163.com</email>
<roles>
<role>Project Manager</role>
<role>Architect</role>
</roles>
</developer>
</developers>
<scm>
<connection>https://gitee.com/wangfugui-ma/aliyun-oss-spring-boot-starter.git</connection>
<developerConnection>scm:git:ssh://git@gitee.com:wangfugui-ma/aliyun-oss-spring-boot-starter.git
</developerConnection>
<url>https://gitee.com/wangfugui-ma/aliyun-oss-spring-boot-starter</url>
</scm>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.2.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.17.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- central发布插件 -->
<plugin>
<groupId>org.sonatype.central</groupId>
<artifactId>central-publishing-maven-plugin</artifactId>
<version>0.4.0</version>
<extensions>true</extensions>
<configuration>
<publishingServerId>masiyi</publishingServerId>
<tokenAuth>true</tokenAuth>
</configuration>
</plugin>
<!-- source源码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- javadoc插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<configuration>
<executable>E:\dev\gpg2\GnuPG\bin\gpg.exe</executable>
<keyname>wangfugui-ma</keyname>
</configuration>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
以下是对这份文档的一些说明:
项目基本信息:properties 以上的部分,虽然都是一些项目信息,但我建议你都保留下来,其中有一些是必须要有的,比如 name、licenses、scm 这几个是必须存在的,其他的我不确定是不是必须的,但还是建议你保留。记得要改成自己的,不要直接复制了就用。
项目依赖:dependencies这部分没有要求,根据自己的项目需求来就好了。
打包插件:上传的jar包必须有 源代码、Javadoc、GPG 这三个部分,都是必须的,所以有三个部分的插件。
由于我自己在本地打包调试的时候不需要这些东西,所以我把一部分插件放在了 profile 里,你 deploy 的时候需要勾选上配置,本地 install 则不需要。
GPG 的插件需要修改下路径,否则会出现找不到 gpg.exe 的异常。
最后面这个 central-publishing-maven-plugin 是用来发布jar包到平台上的,需要修改下 publishingServerId,内容对应前面改的 setting.xml 文件。
配置完pom文件后,你可以先 mvn install -P release 一下,看看有没有报错什么的。
如果你的 Maven 构建的时候出现异常,但异常信息是乱码的:
这种情况下我们给Maven修改下编码,在Maven的运行时参数中添加 -Dfile.encoding=GB2312
即可(测试不好用):
Javadoc有很多警告,缺少 @return 标签,可以改一下,也可以不改,看你心情。
没别的问题就可以准备发布项目了。
发布项目
先 clean 然后再 deploy,会弹出窗口让你输入 GPG 的密码,验证成功后就会开始上传。
如果在 deploy 时出现了这样的异常:
Deployment 2c57742a-ff70-4f5c-aa75-5f50614a68eb (Deployment) failed while publishing
可以到 sonatype 的网站上查看失败的原因:
如果一切顺利的话,你可以在 sonatype 的网站上看到你上传成功的但未发布的maven包:
这个时候我们点击 Publish
,Deployment的状态就会变成 publishing
,意思是正在发布中,大概多十多分钟,它的状态会变为 published
,这时候就正式发布成功了。
发布完成后,可以搜索到我们发布的 jar 包:
地址:https://central.sonatype.com/artifact/top.hjcwzx/dynamic-thread-pool-spring-boot-starter
后续maven中央仓库和阿里镜像仓库等都会自动同步,这样我们就成功发布了我们的项目了。之后如果升级的话,记得要把版本号进行更新,否则是发布不了的。
注意事项
publishingServerId 里面的值要对应setting文件里面的id 之前有gpg秘钥的时候请先导出,如何把原来的删除,否则会一直验证失败 使用mvn clean deploy 命令的时候请指定setting文件地址,如果在idea打包则不需要 Generate User Token 如果重新生成,之前的就会用不了,会报401错误 使用gpg生成秘钥的时候名称一定要填命名空间里面的名称,否则打包会一直验证失败 一定要用我发出来的pom文件里面的结构,否则会打包失败
使用dynamic-thread-pool-spring-boot-starter(动态线程池组件)
需要搭配管理端控制台使用(starter组件上报+管理端动态显示线程池列表以及修改)
地址:https://gitee.com/dynamic-thread-pool/dynamic-thread-pool (需要联系我分享+测试)
使用步骤