公开Java框架开源到Maven中央仓库(避坑)

前言:
gpg下载地址:http://www.gnupg.org/download
安装勾选 kleopatra
下载完成验证 gpg --version

当时为了开源Java框架,真的是绞尽脑汁,耗费很多精力查了很多资料,躺了很多坑,最终的结果无不是以发布失败而告终,现在直接把我直接成功的例子给到大家,同时也带了一点私心,希望自己的开源越来越被多人看到使用和继续完善。
给出开源链接:https://github.com/fyupeng/rpc-netty-framework/

1. 生成秘钥

gpg --full-generate-key

连续敲三个空格后,输入y

记住Passphase,相当于一个密钥库的密码,用来鉴权是不是所有人在使用

最后保存起来,我一般保存到${user.home}/.gnupg,与秘钥存放位置放一起

这里注意一下,默认私钥和公钥会保存在C:\Users\${user_name}\AppData\Roaming\gnupg\目录中

而IDE会找到${user.home}/.gnupg该目录下,如果没有做任何操作,你生成的秘钥通过gpg --list-keys是找不到的

下面会详细给步骤

2. 查看秘钥

gpg --list-keys

获取key Id 来获取秘钥可以为 公钥后16位和8位,推荐16位

3. 发布公钥到公钥服务器

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --send-keys FD953A355469C8AA

无提示、无报错即可

4. 从公钥服务器获取公钥

gpg --keyserver hkp://keyserver.ubuntu.com:11371 --recv-keys FD953A355469C8AA
gpg: key 12E2CADABE0D891E: "fyupeng <[email protected]>" not changed
gpg: Total number processed: 1
gpg:              unchanged: 1

5. 获取公钥列表

C:\Users\fyp01>gpg --list-keys
C:\Users\fyp01\AppData\Roaming\gnupg\pubring.kbx
------------------------------------------------
pub   ed25519 2022-08-20 [SC] [expires: 2024-08-19]
      76591F10A73649202490BA3812E2CADABE0D891E
uid           [ultimate] fyupeng <1160886967@qq.com>
sub   cv25519 2022-08-20 [E] [expires: 2024-08-19]

6. 打印公钥

gpg --armor --export FD953A355469C8AA

7. 打印私钥

gpg --list-secret-keys --keyid-format LONG

8. 发布异常

解决maven-javadoc-plugin报错 警告warning异常

<plugin>
    <groupId>org.apache.maven.pluginsgroupId>
    <artifactId>maven-javadoc-pluginartifactId>
    <version>2.9.1version>
    <configuration>
        <aggregate>trueaggregate>
    configuration>
    <executions>
        <execution>
            <id>attach-javadocsid>
            <goals>
                <goal>jargoal>
            goals>
            
            <configuration>
                <additionalOptions>-Xdoclint:noneadditionalOptions>
            configuration>
        execution>
    executions>
plugin>
  • 解决下面异常
gpg: skipped "FD953A355469C8AA": No secret key
gpg: signing failed: No secret key

将路径C:\Users\fyp01\AppData\Roaming\gnupg下的公钥和私钥复制到${user.home}/.gnupg目录中

  • 解决下面异常
gpg: invalid size of lockfile '/c/Users/fyp01/.gnupg/pubring.kbx.lock'
gpg: cannot read lockfile
gpg: can't lock '/c/Users/fyp01/.gnupg/pubring.kbx'
/c/Users/fyp01/.gnupg/pubring.kbx

删除${user.home}./gnupg目录下的所有.lock文件即可,自动生成的

  • 解决status405异常

也就是put失败,不支持Method的相关操作

确保deploy这个SNATSHOT测试版本后要先看是否校验通过,并且要去close,当然可以再继续release,否则不能发布正式版本

这样正式版本发布会找到已经发布了的测试版本,就给上传了

  • 解决status401异常

身份未校验,建议在buildplugin中都加入gpg校验,否则会报错,并且分开测试和正式校验

<distributionManagement>
    <snapshotRepository>
        
        <id>sonatype-nexus-snapshotsid>
        <url>https://s01.oss.sonatype.org/content/repositories/snapshots/url>
    snapshotRepository>
    
    <repository>
        <id>sonatype-nexus-stagingid>
        <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/url>
    repository>
distributionManagement>

mavensetting.xml

<servers>
    <server>
        <id>sonatype-nexus-snapshotsid>
        <username>${your_sonatype_username}username>
        <password>${your_sonatype_password}password>
    server>
    <server>
        <id>sonatype-nexus-stagingid>
        <username>${your_sonatype_username}username>
        <password>${your_sonatype_password}password>
    server>
servers>

而且发布正式要多一个依赖,主要用于发布,没有会报错

因为这个插件有属性autoReleaseAfterClose,在你手动关闭之后,再次发布会自动发布到相应的正式仓库中

<profiles>
    <profile>
        <id>releaseid>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.sonatype.pluginsgroupId>
                    <artifactId>nexus-staging-maven-pluginartifactId>
                    <version>1.6.7version>
                    <extensions>trueextensions>
                    <configuration>
                        <serverId>sonatype-nexus-stagingserverId>
                        <nexusUrl>https://s01.oss.sonatype.org/nexusUrl>
                        <autoReleaseAfterClose>trueautoReleaseAfterClose>
                    configuration>
                plugin>
            plugins>
        build>
    profile>
profiles>

9. 发布测试

修改version加一个-SNAPSHOT

mvn clean deploy

10. 发布正式

修改version 不要加-SNAPSHOT

mvn clean deploy -P release

可以手动修改,也可以执行

mvn versions:set -DnewVersion=1.0.0

11. 完整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.0modelVersion>

    <groupId>cn.fyupenggroupId>
    <artifactId>rpc-netty-frameworkartifactId>
    <packaging>pompackaging>
    <version>1.0.0version>
	
    <name>rpc-netty-frameworkname>
    
    <url>https://github.com/fyupeng/rpc-netty-frameworkurl>
    <description>基于Netty分布式微服务的RPC框架description>

    <properties>
        <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        <netty.version>4.1.20.Finalnetty.version>
    properties>

    <modules>
        <module>rpc-coremodule>
        <module>rpc-commonmodule>
    modules>

    <dependencies>
        
        <dependency>
            <groupId>com.alibaba.nacosgroupId>
            <artifactId>nacos-clientartifactId>
            <version>1.4.3version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4jgroupId>
                    <artifactId>slf4j-apiartifactId>
                exclusion>
            exclusions>
        dependency>
    dependencies>


    <licenses>
        <license>
            <name>The MIT Licensename>
            <url>https://github.com/fyupeng/rpc-netty-framework/blob/main/LICENCEurl>
        license>
    licenses>

    <developers>
        <developer>
            <name>fyupengname>
            <email>[email protected]email>
        developer>
    developers>

    <scm>
        <connection>scm:git:https://github.com/fyupeng/rpc-netty-framework.gitconnection>
        <developerConnection>scm:git:https://github.com/fyupeng/rpc-netty-framework.gitdeveloperConnection>
        <url>https://github.com/fyupeng/rpc-netty-frameworkurl>
    scm>

    <distributionManagement>
        <snapshotRepository>
            
            <id>sonatype-nexus-snapshotsid>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots/url>
        snapshotRepository>
        
        <repository>
            <id>sonatype-nexus-stagingid>
            <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/url>
        repository>
    distributionManagement>


    <build>
        <finalName>rpc-netty-frameworkfinalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-compiler-pluginartifactId>
                <configuration>
                    <source>1.8source>
                    <target>1.8target>
                configuration>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-source-pluginartifactId>
                <executions>
                    <execution>
                        <id>attach-sourcesid>
                        <goals>
                            <goal>jar-no-forkgoal>
                        goals>
                    execution>
                executions>
            plugin>
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-javadoc-pluginartifactId>
                <executions>
                    <execution>
                        <id>attach-javadocsid>
                        <goals>
                            <goal>jargoal>
                        goals>
                        
                        <configuration>
                            <additionalOptions>-Xdoclint:noneadditionalOptions>
                        configuration>
                    execution>
                executions>
            plugin>
            
            
            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-gpg-pluginartifactId>
                <version>1.5version>
                <executions>
                    <execution>
                        <id>sign-artifactsid>
                        <phase>verifyphase>
                        <goals>
                            <goal>signgoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>

    <profiles>
        <profile>
            <id>jdk-18id>
            <activation>
                <activeByDefault>trueactiveByDefault>
                <jdk>1.8jdk>
            activation>
            <properties>
                <maven.compiler.source>1.8maven.compiler.source>
                <maven.compiler.target>1.8maven.compiler.target>
                <maven.compiler.compilerVersion>1.8maven.compiler.compilerVersion>
            properties>
        profile>

        <profile>
            <id>releaseid>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.sonatype.pluginsgroupId>
                        <artifactId>nexus-staging-maven-pluginartifactId>
                        <version>1.6.7version>
                        <extensions>trueextensions>
                        <configuration>
                            <serverId>sonatype-nexus-stagingserverId>
                            <nexusUrl>https://s01.oss.sonatype.org/nexusUrl>
                            <autoReleaseAfterClose>trueautoReleaseAfterClose>
                        configuration>
                    plugin>
                    
                    <plugin>
                        <groupId>org.apache.maven.pluginsgroupId>
                        <artifactId>maven-gpg-pluginartifactId>
                        <version>1.5version>
                        <executions>
                            <execution>
                                <id>sign-artifactsid>
                                <phase>verifyphase>
                                <goals>
                                    <goal>signgoal>
                                goals>
                            execution>
                        executions>
                    plugin>
                plugins>
            build>
        profile>

    profiles>



project>

maven目录中setting.xml配置

<servers>
    <server>
        <id>sonatype-nexus-snapshotsid>
        <username>${your_sonatype_username}username>
        <password>${your_sonatype_password}password>
    server>
    <server>
        <id>sonatype-nexus-stagingid>
        <username>${your_sonatype_username}username>
        <password>${your_sonatype_password}password>
    server>
servers>
<profile>
        <id>ossrhid>
        <activation>
            <activeByDefault>trueactiveByDefault>
        activation>
        <properties>
        	
            <gpg.keyname>${your_gpg_keyId}gpg.keyname>
          <gpg.executable>D:\software\GnuPG\bin\gpggpg.executable>
          <gpg.passphrase>${your_gpg_passphrase}gpg.passphrase>
        properties>
     profile>

你可能感兴趣的:(java,开源,maven)