Java Maven项目推送到 Maven 中心仓库

打印 上一主题 下一主题

主题 922|帖子 922|积分 2766

预备阶段

namespace 域名认证

当需要在 sonatype 认证 com.xxx命名空间时,需要将 @.xxx.com 配置域名剖析。
记录范例:TXT
文本内容:验证的 key。


GPG 公私钥天生

GPG 下载地址:https://www.gnupg.org/download/index.html
Mac 可以利用 brew install gpg直接安装
利用方式可参考:
天生证书
  1. $ gpg --gen-key
复制代码


查询证书
  1. $ gpg --list-keys
  2. gpg: 正在检查信任度数据库
  3. gpg: marginals needed: 3  completes needed: 1  trust model: pgp
  4. gpg: 深度:0  有效性:  1  已签名:  0  信任度:0-,0q,0n,0m,0f,1u
  5. gpg: 下次信任度数据库检查将于 2027-04-06 进行
  6. [keyboxd]
  7. ---------
  8. pub   ed25519 2024-04-06 [SC] [有效至:2027-04-06]
  9.       ABC
  10. uid             [ 绝对 ] xxx <xxx@163.com>
  11. sub   cv25519 2024-04-06 [E] [有效至:2027-04-06]
复制代码
上传公钥到公钥管理服务器
  1. $ gpg --keyserver keyserver.ubuntu.com --send-keys ABC
  2. gpg: 正在发送密钥 ABC 到 hkp://keyserver.ubuntu.com
复制代码
假如报错 gpg: keyserver send failed: No route to host可以参考该文章上传公钥:https://vayne.cc/2022/03/13/gpg/
推送阶段

pom.xml 文件配置

配置 url
  1.     <url>https://github.com/xxx/yyy</url>
复制代码
配置 license
  1.     <licenses>
  2.         <license>
  3.             <name>The Apache Software License, Version 2.0</name>
  4.             <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  5.             <distribution>repo</distribution>
  6.         </license>
  7.     </licenses>
复制代码
配置 issueManagement
  1.             github        <url>https://github.com/xxx/yyy</url>/issues   
复制代码
配置 SCM
  1.             scm:git:https://github.com/xxx/yyy.git        scm:git:https://github.com/xxx/yyy.git        <url>https://github.com/xxx/yyy</url>   
复制代码
配置开辟者信息
  1.     <developers>
  2.         <developer>
  3.             <name>xxx</name>
  4.             <email>xxx@zzz.com</email>
  5.             <url>https://github.com/xxx</url>
  6.         </developer>
  7.     </developers>
复制代码
通用插件配置
  1.     <build>
  2.         <plugins>
  3.             <plugin>
  4.                 <groupId>org.codehaus.mojo</groupId>
  5.                 <artifactId>flatten-maven-plugin</artifactId>
  6.                 <version>1.5.0</version>
  7.                 <configuration>
  8.                     <updatePomFile>true</updatePomFile>
  9.                     <flattenMode>oss</flattenMode>
  10.                 </configuration>
  11.                 <executions>
  12.                     <execution>
  13.                         <id>flatten</id>
  14.                         <phase>process-resources</phase>
  15.                         <goals>
  16.                             <goal>flatten</goal>
  17.                         </goals>
  18.                     </execution>
  19.                     <execution>
  20.                         <id>flatten.clean</id>
  21.                         <phase>clean</phase>
  22.                         <goals>
  23.                             <goal>clean</goal>
  24.                         </goals>
  25.                     </execution>
  26.                 </executions>
  27.             </plugin>
  28.             
  29.             <plugin>
  30.                 <groupId>org.apache.maven.plugins</groupId>
  31.                 <artifactId>maven-source-plugin</artifactId>
  32.                 <version>3.1.0</version>
  33.                 <inherited>true</inherited>
  34.                 <executions>
  35.                     <execution>
  36.                         <id>attach-sources</id>
  37.                         <goals>
  38.                             <goal>jar</goal>
  39.                         </goals>
  40.                     </execution>
  41.                 </executions>
  42.                 <configuration>
  43.                     <excludeResources>true</excludeResources>
  44.                     <useDefaultExcludes>true</useDefaultExcludes>
  45.                 </configuration>
  46.             </plugin>
  47.             <plugin>
  48.                 <groupId>org.apache.maven.plugins</groupId>
  49.                 <artifactId>maven-javadoc-plugin</artifactId>
  50.                 <version>3.1.0</version>
  51.                 <inherited>true</inherited>
  52.                 <executions>
  53.                     <execution>
  54.                         <id>bundle-sources</id>
  55.                         <phase>package</phase>
  56.                         <goals>
  57.                             <goal>jar</goal>
  58.                         </goals>
  59.                     </execution>
  60.                 </executions>
  61.                 <configuration>
  62.                     <maxmemory>1024</maxmemory>
  63.                     <encoding>UTF-8</encoding>
  64.                     <show>protected</show>
  65.                     <notree>true</notree>
  66.                     
  67.                     <failOnError>false</failOnError>
  68.                     <doclint>none</doclint>
  69.                 </configuration>
  70.             </plugin>
  71.         </plugins>
  72.     </build>
复制代码
Maven 上传插件配置
  1.     <profiles>
  2.         <profile>
  3.             <id>release</id>
  4.             <build>
  5.                 <plugins>
  6.                     <plugin>
  7.                         <groupId>org.apache.maven.plugins</groupId>
  8.                         <artifactId>maven-gpg-plugin</artifactId>
  9.                         <version>1.6</version>
  10.                         <executions>
  11.                             <execution>
  12.                                 <id>sign-artifacts</id>
  13.                                 <phase>verify</phase>
  14.                                 <goals>
  15.                                     <goal>sign</goal>
  16.                                 </goals>
  17.                             </execution>
  18.                         </executions>
  19.                         <configuration>
  20.                             <gpgArguments>
  21.                                 
  22.                                 <arg>--pinentry-mode</arg>
  23.                                 <arg>loopback</arg>
  24.                             </gpgArguments>
  25.                         </configuration>
  26.                     </plugin>
  27.                     
  28.                     <plugin>
  29.                         <groupId>org.sonatype.central</groupId>
  30.                         <artifactId>central-publishing-maven-plugin</artifactId>
  31.                         <version>0.4.0</version>
  32.                         <extensions>true</extensions>
  33.                         <configuration>
  34.                             <publishingServerId>central</publishingServerId>
  35.                             <tokenAuth>true</tokenAuth>
  36.                             <autoPublish>true</autoPublish>
  37.                             <excludeArtifacts>
  38.                                 <excludeArtifact>xxx-yyy</excludeArtifact>
  39.                             </excludeArtifacts>
  40.                         </configuration>
  41.                     </plugin>
  42.                 </plugins>
  43.             </build>
  44.         </profile>
  45.     </profiles>
复制代码
settings.xml 文件配置
  1.   <servers>
  2.     <server>
  3.       <id>central</id>
  4.       <username>xxx</username>
  5.       <password>yyy</password>
  6.     </server>
  7.   </servers>
  8.   <profiles>
  9.     <profile>
  10.       <id>gpg</id>
  11.       <activation>
  12.         <activeByDefault>true</activeByDefault>
  13.       </activation>
  14.       <properties>
  15.         <gpg.executable>gpg</gpg.executable>
  16.         <gpg.keyname>xxx@zzz.com</gpg.keyname>
  17.         <gpg.passphrase>passphrase</gpg.passphrase>
  18.         <gpg.useagent>true</gpg.useagent>
  19.       </properties>
  20.     </profile>
  21.   </profiles>
复制代码
实验构建并上传
  1. $ mvn clean deploy -Prelease
复制代码
上传结果


报错参考


  • Javadocs must be provided but not found in entries:需要提供 Javadoc
  • License information is missing:需要提供 license 信息
  • Project URL is not defined:需要界说项目 URL 信息
  • SCM URL is not defined:需要界说 SCM 信息
  • version cannot be a SNAPSHOT:Maven 中心仓库不支持推送快照版本
参考文档

分享并记录所学所见

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

卖不甜枣

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表