发布jar包到maven中央仓库之pom文件

完整过程参考:发布jar包到maven中央仓库教程

发布jar包到maven中央仓库需要对本地maven的配置文件进行修改,我们需要在节点下增加以下内容

<server>
    <id>sonatype</id>
    <username>liqingcan</username>
    <password>youpassword</password>
</server>

其中username和password分别是你注册sonatype时的账号名和密码。https://issues.sonatype.org/secure/Dashboard.jspa

完整的项目pom文件的结构如下方样例,建议直接复制过来进行修改。

<?xml version="1.0"?>
<project
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
        xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.github.lqccan</groupId>
    <artifactId>wechat-work-bot</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <url>https://github.com/lqccan/wechat-work-bot</url>

    <name>wechat-work-bot</name>
    <description>a sdk for wechat work bot</description>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <name>liqingcan</name>
            <email>1102946234@qq.com</email>
        </developer>
    </developers>
    <scm>
        <connection>https://github.com/lqccan/wechat-work-bot</connection>
        <developerConnection>https://github.com/lqccan/wechat-work-bot</developerConnection>
        <url>https://github.com/lqccan/wechat-work-bot</url>
    </scm>

    <properties>
        <java.version>1.8</java.version>
        <javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <!--阿里巴巴的json包-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.62</version>
        </dependency>
        <!--hutool工具包-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.1.12</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <!-- 这个id就是打包时的 -P 参数 -->
            <id>release</id>
            <build>
                <plugins>
                    <!-- Source插件-->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <version>2.2.1</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar-no-fork</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- Javadoc插件 -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.9.1</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jar</goal>
                                </goals>
                                <!-- -Xdoclint:none 是为了避免生成apidoc的时候检查过于严格而报错-->
                                <configuration>
                                    <additionalparam>-Xdoclint:none</additionalparam>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <!-- GPG加密插件 -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-gpg-plugin</artifactId>
                        <version>1.6</version>
                        <executions>
                            <execution>
                                <phase>verify</phase>
                                <goals>
                                    <goal>sign</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <!-- snapshotRepository与repository的id应与setting.xml中添加的server的id一致 -->
            <distributionManagement>
                <snapshotRepository>
                    <id>sonatype</id>
                    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
                </snapshotRepository>
                <repository>
                    <id>sonatype</id>
                    <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
                </repository>
            </distributionManagement>
        </profile>
    </profiles>

</project>

觉得内容还不错?打赏个钢镚鼓励鼓励!!👍