原创

个人工具包推送maven中央仓库过程记录

1、大致步骤

  • 申请sonatype账号并提交工单
  • 设置域名的dns解析
  • 设置gpg,windows上需要配置系统环境变量
  • 配置maven环境和pom配置

2、要点说明

2.1、dns解析

txt为工单编号,value为工单的全网址

2.2、maven环境配置

增加sever配置
<server>
  <id>ossrh</id>
  <username>chenxing</username>
  <password>xxxxx</password>
</server>

增加profile
<profile>
  <id>ossrh</id>
  <activation>
    <activeByDefault>false</activeByDefault>
  </activation>

  <properties>
    <gpg.executable>gpg2</gpg.executable>
    <gpg.passphrase>BD6F2324</gpg.passphrase>
  </properties>
</profile>

gpg.passphrase的key是 命令 gpg --list-signatures --keyid-format 0xshort: 获取的

2.3、pom配置

<?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>com.cxztt</groupId>
    <artifactId>chenxingToolSet</artifactId>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>search</module>
        <module>core</module>
        <module>net</module>
    </modules>

    <name>chenxingToolSet</name>
    <!-- FIXME change it to the project's website -->
    <url>https://www.gzcx.net</url>
    <description>主人翁开发工具集合</description>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <compile.version>1.8</compile.version>
        <junit.version>4.13.2</junit.version>
        <lombok.version>1.18.2</lombok.version>
        <gpg.keyname>BD6F2324</gpg.keyname>
    </properties>

    <dependencies>
        <!-- 全局单元测试 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
            <optional>true</optional>
        </dependency>
    </dependencies>


    <licenses>
        <license>
            <name>Mulan Permissive Software License,Version 2</name>
            <url>https://license.coscl.org.cn/MulanPSL2</url>
        </license>
    </licenses>

    <developers>
        <developer>
            <name>chenxing</name>
            <email>763073825@qq.com</email>
        </developer>
    </developers>

    <scm>
        <connection>scm:git@github.com:chen-xing/chenxingToolSet.git</connection>
        <developerConnection>scm:git@github.com:chen-xing/chenxingToolSet.git</developerConnection>
        <url>git@github.com:chen-xing/chenxingToolSet.git</url>
    </scm>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>
    <build>
        <pluginManagement>
        <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.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.7</version>
                <extensions>true</extensions>
                <configuration>
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>
            <!-- Gpg Signature -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>ossrh</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        </pluginManagement>
    </build>
</project>

2.4、执行打包上传操作

mvn clean deploy -Dmaven.test.skip=true

3、存在的问题

sonatype仓库截图

解决办法:删除本地仓库中的相同的jar,在另一个项目中引用这个pom

4、参考

正文到此结束
本文目录