maven插件上传本地jar包到maven*仓库

settings配置(如果设置后有问题,可以重启idea,保证重新加载settings文件):

<!-- 上传jar包到maven*仓库配置start -->
<server>
<id>ossrh</id>
<username>*****</username>
<password>****</password>
</server>
<!-- 上传jar包到maven*仓库配置end -->

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>com.github.z-pro</groupId>
<artifactId>dztools</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging> <name>${project.groupId}:${project.artifactId}</name>
<description>The test uploads the jar to the maven central repository</description>
<url>https://github.com/z-pro/OSSRH-52405</url> <properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.deploy.skip>true</maven.deploy.skip>
</properties> <dependencies>
<!-- ... -->
</dependencies> <!-- 许可证信息 -->
<licenses>
<!-- Apache许可证 -->
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
<!-- MIT许可证 -->
<!-- <license>
<name>MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
</license>-->
</licenses>
<!-- SCM信息 -> git在github上托管 -->
<scm>
<connection>scm:git:git://github.com/z-pro/OSSRH-52405.git</connection>
<developerConnection>scm:git:ssh://github.com/z-pro/OSSRH-52405.git</developerConnection>
<url>https://github.com/z-pro/OSSRH-52405/tree/master</url>
</scm>
<!-- 开发者信息 -->
<developers>
<developer>
<name>z-pro</name>
<email>380368126@qq.com</email>
<url>https://github.com/z-pro</url>
</developer>
</developers> <!-- 使用个人资料:由于生成javadoc和源jar以及使用GPG签署组件是一个相当耗时的过程,因此这些执行通常与正常的构建配置隔离并移动到配置文件中。然后,在通过激活配置文件执行部署时,将使用此配置文件。 -->
<profiles>
<profile>
<id>release</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<!-- <properties>
<gpg.executable>gpg</gpg.executable>
<gpg.passphrase>****</gpg.passphrase>
<gpg.executable>D:\***\Gpg4win\bin\gpg.exe</gpg.executable>
<gpg.homedir>C:/Users/***/AppData/Roaming/gnupg/</gpg.homedir>
</properties>-->
<build>
<plugins>
<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>
<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>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- 要生成Javadoc和Source jar文件,您必须配置javadoc和源Maven插件 -->
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>-->
<!-- <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> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<aggregate>true</aggregate>
<charset>UTF-8</charset>
<encoding>UTF-8</encoding>
<docencoding>UTF-8</docencoding>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
<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>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>-->
<!-- <plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</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-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>-->
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
</configuration>
</plugin>--> </plugins>
</build>
<!-- 【注】snapshotRepository 与 repository 中的 id 一定要与 setting.xml 中 server 的 id 保持一致! -->
<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
</profile>
</profiles>
</project>

参考:https://blog.csdn.net/qq_38225558/article/details/94381467

https://central.sonatype.org/pages/apache-maven.html#gpg-signed-components

https://www.jianshu.com/p/1bd36edab4ee

https://blog.csdn.net/alinyua/article/details/83687250

提交:https://oss.sonatype.org

搜索上线:https://search.maven.org/

上一篇:java – CustomArrayAdapter中的NullPointerException


下一篇:maven上传本地jar包到私服