Skip to content

发布jar包到Maven中央仓库

https://central.sonatype.com/publishing/deployments

xml
<server>
  <id>ossrh</id>
  <username>drpPHH</username>
  <password>x x x</password>
</server>

修改pom中的版本号

访问https://central.sonatype.com/publishing/deployments,使用github账号登录

bash

构建部署

准备:在项目的pom.xml文件中定义distributionManagement块

xml
<!-- 部署管理配置,基本不需要修改,原来是必须要配的 -->
<!-- 新的发布方式已经不需要该配置了,可以删掉 -->
<distributionManagement>
    <snapshotRepository>
        <id>ossrh</id>
        <name>OSS Snapshots Repositories</name>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
    </snapshotRepository>
    <repository>
        <id>ossrh</id>
        <name>OSS Staging Repositories</name>
        <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
    </repository>
</distributionManagement>

使用插件部署Jar

xml
<build>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>
        <!-- Compiler -->
        <!-- 编译插件,插件是必须的 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.14.0</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
                <encoding>${project.build.sourceEncoding}</encoding>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>${lombok.version}</version>
                    </path>
                    <!-- <path> -->
                    <!--     <groupId>org.springframework.boot</groupId> -->
                    <!--     <artifactId>spring-boot-configuration-processor</artifactId> -->
                    <!--     <version>${spring-boot.version}</version> -->
                    <!-- </path> -->
                </annotationProcessorPaths>
                <compilerArgs>
                    <arg>-parameters</arg>
                </compilerArgs>
            </configuration>
        </plugin>
        <!-- Source -->
        <!-- jar源码包生成插件,插件是必须的 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <!-- 源码包随着项目打成的jar包安装到本地仓库或者私服、公服 -->
                <attach>true</attach>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar-no-fork</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- gen javadoc plugin -->
        <!-- javadoc生成插件,插件是必须的 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>3.11.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- 禁用严格语法检测 -->
                <doclint>none</doclint>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>release</id>
        <build>
            <plugins>
                <!-- GPG -->
                <!-- GPG签名插件,插件是必须的 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-gpg-plugin</artifactId>
                    <version>3.2.7</version>
                    <configuration>
                        <gpgArguments>
                            <arg>--pinentry-mode</arg>
                            <arg>loopback</arg>
                            <arg>--passphrase</arg>
                            <arg>istr.cn</arg>
                        </gpgArguments>
                    </configuration>
                    <executions>
                        <execution>
                            <id>sign-artifacts</id>
                            <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.7.0</version>
                    <extensions>true</extensions>
                    <configuration>
                        <!-- 注意:这类必须要和Maven配置环境中的server id对应上 -->
                        <publishingServerId>ossrh</publishingServerId>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Intellij IDEA Use settings from .mvn/maven.config 勾选的作用

https://bbs.huaweicloud.com/blogs/456917

最近更新