美文网首页
发布一个maven包

发布一个maven包

作者: yichen_china | 来源:发表于2023-09-24 15:13 被阅读0次

如下是完整的pom.xml,最精简版

<?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>
    <properties>
        <java.home>${env.JAVA_HOME}</java.home>
        <java.version>1.8</java.version>
        <project.version>0.0.1-SNAPSHOT</project.version>
    </properties>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.11</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>io.gitee.wokaixin</groupId>
    <artifactId>yunque-message-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>yunque-message-client</name>
    <description>yunque-message-client</description>
    <packaging>jar</packaging>
    <url>https://gitee.com/wokaixin/</url>
    <developers>
        <developer>
            <name>wokaixin</name>
            <email>2782268022@163.com</email>
            <organization>https://gitee.com/wokaixin/</organization>
        </developer>
    </developers>
    <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>
    <scm>
        <connection>scm:git:https://gitee.com/wokaixin/yunque-message-client-java.git</connection>
        <developerConnection>scm:git:https://gitee.com/wokaixin/yunque-message-client-java.git</developerConnection>
        <url>https://gitee.com/wokaixin/yunque-message-client-java.git</url>
        <tag>v${project.version}</tag>
    </scm>
    <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.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.5.5</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.78</version>
        </dependency>
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.24.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>2.5.5</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
        </dependency>
    </dependencies>
    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.plugins</groupId>
                        <artifactId>nexus-staging-maven-plugin</artifactId>
                        <version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                        </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>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.4</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.10.3</version>
                        <configuration>
                            <show>private</show>
                            <nohelp>true</nohelp>
                            <charset>UTF-8</charset>
                            <encoding>UTF-8</encoding>
                            <docencoding>UTF-8</docencoding>
                            <!-- 临时解决不规范的Javadoc生成报错 -->
                            <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>3.1.0</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <build>
        <plugins>
            <!--发布源码插件-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

新建项目,包名需要验证。

去这个地址注册账号https://issues.sonatype.org
创建一个项目,首先需要创建一个问题,如下图

tupian.png

包名,也uri地址规范要注意。
我没用自己域名,如果用自己域名,需要域名解析认证。
我用的gitee包名,就在gitee账号下创建一个仓库,并且设为开放状态,用来认证,
如下:https://gitee.com/wokaixin/OSSRH-95298.git
wokaixin 是我的空间名。
OSSRH-95298 是我新建的这个问题编号。
要保证项目的包名地址 加这个问题编号可以打开。
然后等待审核,一般1-10分钟就可以通过。如果没通过,会有回复信息,查看原因。

配置maven账号

maven的settings.xml

<!--需要添加账号密码-->
<server>
# 这个id要和pom包里面的 <snapshotRepository> id一样
      <id>ossrh</id>
      <username>sonatype账号</username>
      <password>sonatype密码</password>
</server>

特别说明下nexus-staging-maven-plugin插件

            <plugin>
                <groupId>org.sonatype.plugins</groupId>
                <artifactId>nexus-staging-maven-plugin</artifactId>
                <version>1.6.7</version>
                <extensions>true</extensions>
                <configuration>
# 这个id要和maven的settings.xml  <server>里id一样
                    <serverId>ossrh</serverId>
                    <nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
                    <autoReleaseAfterClose>true</autoReleaseAfterClose>
                </configuration>
            </plugin>

staging puglin,用于自动执行发布阶段(免手动)

发布命令

快照版本
mvn clean install deploy
稳定版本
mvn clean install deploy -P release

因为deploy之后,默认状态为open,你需要在后台[https://oss.sonatype.org]
先关闭->在 开启

当然,加上这个插件,将autoReleaseAfterClose指定为true,即可自动发布

Release完成后
可以在https://s01.oss.sonatype.org 搜索到你的包名查看到。

约需要等待两三个小时,在 [https://search.maven.org]库查到了
(https://cloud.tencent.com/developer/tools/blog-entry?target=https%3A%2F%2Fsearch.maven.org%2F) 和 https://mvnrepository.com 便可以搜到自己发布的依赖了!!!!

同步到第三方仓库,如阿里云等会更慢

相关文章

网友评论

      本文标题:发布一个maven包

      本文链接:https://www.haomeiwen.com/subject/exofbdtx.html