Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说把自己的java库发布到maven公共仓库,像其他普通jar一样使用它,希望能够帮助你!!!。
GnuPG needs to construct a user ID to identify your key.
Real name: zq2599
Email address: zq2599@gmail.com
You selected this USER-ID:
"zq2599 <zq2599@gmail.com>"
Change (N)ame, (E)mail, or (O)kay/(Q)uit? O
gpg: key 11027EJIHGFEDCBA marked as ultimately trusted
gpg: directory '/Users/will/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/Users/will/.gnupg/openpgp-revocs.d/561AEE4EA92EE3E4C389941811027E9876543210.rev'
public and secret key created and signed.
pub rsa3072 2021-11-10 [SC] [expires: 2023-11-10]
561AEE4EA92EE3E4C389941811027E9876543210
uid zq2599 <zq2599@gmail.com>
sub rsa3072 2021-11-10 [E] [expires: 2023-11-10]
gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys 561AEE4EA92EE3E4C389941811027E9876543210
<server>
<id>ossrh</id>
<username>zq2599</username>
<password>12345678</password>
</server>
<profile>
<id>gpg</id>
<properties>
<!-- 由于我的电脑装的gpg2,所以需要指定执行gpg2,否则会报错 -->
<gpg.executable>gpg2</gpg.executable>
<gpg.passphrase>abcdefgh</gpg.passphrase>
</properties>
</profile>
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.zq2599</groupId>
<artifactId>opencv-linux</artifactId>
<version>0.0.3</version>
<name>opencv-linux</name>
<description>opencv-linux</description>
<!-- 1. url必须要有,不然远程提交时会返回错误 -->
<url>https://github.com/zq2599/opencv-client</url>
<properties>
<java.version>1.8</java.version>
</properties>
<packaging>jar</packaging>
<!-- 2. 开源证书 -->
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<!-- 3. 源码仓库信息 -->
<scm>
<connection>scm:git:git@github.com:zq2599/opencv-client.git</connection>
<developerConnection>scm:git:git@github.com:zq2599/opencv-client.git</developerConnection>
<url>https://github.com/zq2599/opencv-client/tree/main</url>
</scm>
<!-- 4. 开发人员信息 -->
<developers>
<developer>
<name>zq2599</name>
<email>zq2599@gmail.com</email>
<organization>https://github.com/zq2599</organization>
<timezone>+8</timezone>
</developer>
</developers>
<!-- 5. 上传的仓库地址,以及使用哪个账号密码配置 -->
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.18</version>
</dependency>
</dependencies>
<build>
<!-- 配置好每个插件的属性 -->
<pluginManagement>
<plugins>
<!-- 6. 上传到sonatype的插件 -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<!-- 这里的id必须要和全局配置中的server一致 -->
<serverId>ossrh</serverId>
<!-- 这个地址,一定要和issue的评论中给出的地址一致! -->
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<!-- 如果希望发布后自动执行close和release操作,此处可以调整为true -->
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- 7. 上传源码的插件 -->
<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>
<!-- 8. 生成doc文档的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<inherited>true</inherited>
<executions>
<execution>
<id>bundle-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<maxmemory>1024</maxmemory>
<encoding>UTF-8</encoding>
<show>protected</show>
<notree>true</notree>
<!-- Avoid running into Java 8's very restrictive doclint issues -->
<failOnError>false</failOnError>
<doclint>none</doclint>
</configuration>
</plugin>
<!-- 9. 编译构建maven工程的插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<!-- 10. 确定要使用哪些插件 -->
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<!-- 11. 生成签名,确定使用那个gpg秘钥 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<!-- 必须和配置中的gpg校验id一致 -->
<id>gpg</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
mvn clean javadoc:jar deploy -P release
...
[INFO] Installing /Users/zhaoqin/github/blog_demos/opencv-linux/target/opencv-linux-0.0.3-sources.jar.asc to /Users/zhaoqin/github/blog_demos/opencv-linux/target/nexus-staging/staging/543da2cd9af848/io/github/zq2599/opencv-linux/0.0.3/opencv-linux-0.0.3-sources.jar.asc
[INFO] Performing remote staging...
[INFO]
[INFO] * Remote staging into staging profile ID "543da2cd9abc12"
[INFO] * Created staging repository with ID "iogithubzq2599-1008".
[INFO] * Staging repository at https://s01.oss.sonatype.org:443/service/local/staging/deployByRepositoryId/iogithubzq2599-1008
[INFO] * Uploading locally staged artifacts to profile io.github.zq2599
Uploading to ossrh:
...
https://s01.oss.sonatype.org:443/service/local/staging/deployByRepositoryId/iogithubzq2599-1008/io/github/zq2599/opencv-linux/0.0.3/opencv-linux-0.0.3-sources.jar.asc (659 B at 1.2 kB/s)
[INFO] * Upload of locally staged artifacts finished.
[INFO] * Closing staging repository with ID "iogithubzq2599-1008".
Waiting for operation to complete...
...
[INFO] Remote staged 1 repositories, finished with success.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.199 s
[INFO] Finished at: 2021-11-12T08:08:37+08:00
<dependency>
<groupId>io.github.zq2599</groupId>
<artifactId>opencv-linux</artifactId>
<version>0.0.3</version>
</dependency>
今天的分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。