• java
  • go
  • 数据库
  • linux
  • 中间件
  • 书
  • 源码
  • 夕拾

  • java
  • go
  • 数据库
  • linux
  • 中间件
  • 书
  • 源码
  • 夕拾

将jar推到mvn公有库

  • 注册JIRA账号
  • 创建issue
  • 推送
    • 创建gpg密钥
    • 完善pom信息
  • 补充
    • snapshot和release
    • gpg问题

记一次发布jar到mvn中央库的操作…

注意: 最好把自己要发布的项目域名买下来…..

注册JIRA账号

  • 注册账号地址

创建issue

创建链接

数据填写的示例

  • 数据填写完毕后,工作人员会要求认证group-id的域名
    • Add a TXT record to your DNS referencing this JIRA ticket: OSSRH-53070 (Fastest)
    • Setup a redirect to your Github page (if it does not already exist)

推送

  • 认证完毕后,该issue变为resolve状态,剩下的就是将项目推到指定仓库了,主要流程如下:
    • 使用gpg创建公密钥,将公钥推送到认证服务器上
    • 完善pom.xml信息,在maven的配置文件的server中加入自己注册sonatype时的账号密码

创建gpg密钥

  1. 创建 gpg –gen-key,中间的密码要记住
  2. 查看 gpg –list-key
  3. 上传至服务器
    • gpg –keyserver hkp://keyserver.ubuntu.com:11371 –send-keys 你的公钥,第二步骤查询时的公钥]
    • gpg –keyserver hkp://pool.sks-keyservers.net –send-keys
  4. 在服务器上查询你的公钥 将–send-keys改为 –recv-keys即可

完善pom信息

  • 主要包含以下信息:
    1. 项目信息
    2. 开发者信息
    3. 开源协议
    4. scm
    5. 发布地址,插件,工具等
  • 发布 mvn clean deploy -p sonatype (指定profile)
  • 示例如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
        <name>detachment-base</name>
    <description>detachment basic, utils</description>
    <url>https://github.com/haoxpdp/detachment-base.git</url>


    <licenses>
    <license>
    <name>The ApacheSoftware License, Version 2.0</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    <distribution>repo</distribution>
    </license>
    </licenses>

    <developers>
    <developer>
    <name>haoxp</name>
    <email>haoxpdp@outlook.com</email>
    <url>https://www.haoxpdp.com</url>
    </developer>
    </developers>
    <scm>
    <tag>master</tag>
    <connection>https://github.com/haoxpdp/detachment-base</connection>
    <developerConnection>https://github.com/haoxpdp/</developerConnection>
    <url>https://github.com/haoxpdp/detachment-base.git</url>
    </scm>
    <profiles>
    <profile>
    <id>release</id>
    <build>
    <plugins>
    <!-- mvn clean deploy -Dmaven.test.skip=true -P release -->
    <plugin>
    <groupId>org.sonatype.plugins</groupId>
    <artifactId>nexus-staging-maven-plugin</artifactId>
    <version>1.6.3</version>
    <extensions>true</extensions>
    <configuration>
    <!-- 和settings.xml中配置的server id 一样,配置自己的注册时用的用户名密码 -->
    <serverId>sonatype</serverId>
    <nexusUrl>https://oss.sonatype.org/</nexusUrl>
    <autoReleaseAfterClose>true</autoReleaseAfterClose>
    </configuration>
    </plugin>
    <!-- mvn versions:set -DnewVersion=1.0.0-RELEASE -->
    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>versions-maven-plugin</artifactId>
    <version>2.7</version>
    <configuration>
    <generateBackupPoms>false</generateBackupPoms>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.5.1</version>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    </configuration>
    </plugin>
    <!-- Source -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>3.0.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.10.4</version>
    <executions>
    <execution>
    <phase>package</phase>
    <goals>
    <goal>jar</goal>
    </goals>
    <configuration>
    <show>private</show>
    <nohelp>true</nohelp>
    <charset>UTF-8</charset>
    <encoding>UTF-8</encoding>
    <docencoding>UTF-8</docencoding>
    <additionalparam>-Xdoclint:none</additionalparam>
    </configuration>
    </execution>
    </executions>
    </plugin>

    <!-- 生成asc 校验文件 -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-gpg-plugin</artifactId>
    <version>1.5</version>
    <executions>
    <execution>
    <!-- 必须和配置中的gpg校验id一致 -->
    <id>release</id>
    <phase>verify</phase>
    <goals>
    <goal>sign</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
    <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>

    补充

    snapshot和release

  1. snapshot版本按照上述步骤直接发布,然后就能直接在自己的项目中引入了,不过记得加快照仓库
  2. release版本需要一段时间同步

gpg问题

作者发布release时遇到gpg总是在(pool.sks-keyservers.net)查不到的问题,但是用命令总能查到。比较奇怪,按照报错的地址打开该服务器,点击上传公钥,总超时,然后该页面变为nginx默认页面。再次执行推送,认证服务器换成了(keyserver.ubuntu.com:11371 ),再次将公钥推到该地址,再次执行deploy,成功。

mvn-settings文件翻译
spring循环依赖问题
  1. 1. 注册JIRA账号
  2. 2. 创建issue
  3. 3. 推送
    1. 3.1. 创建gpg密钥
    2. 3.2. 完善pom信息
  4. 4. 补充
    1. 4.1. snapshot和release
    2. 4.2. gpg问题
© 2023 haoxp
Hexo theme