当前位置: 首页 > news >正文

【TOOLS】Project 2 Maven Central

发布自己的项目到maven中央仓库

Maven Central Account

  1. 访问:https://central.sonatype.com/,点击右上角,根据提示注册账号
    在这里插入图片描述
  2. 构建User token ,用于访问中央仓库的API:
    • 点击右上角,查看账户
    • 点击Generate User Token,根据提示,构建个人访问令牌
    • 将获取的User Token xml代码配置到maven配置文件settings.xml 的servers属性中
      在这里插入图片描述
      在这里插入图片描述

POM.xml

配置需要发布的项目中的POM.xml文件

  1. 配置编译项目的java版本
<properties><maven.compiler.source>11</maven.compiler.source><maven.compiler.target>11</maven.compiler.target><java.version>11</java.version>
</properties>
  1. 配置项目名称、项目地址、打包方式
<name>xx xx</name>
<description>desc</description>
<url>https://github.com/xx/xx.xx.xx</url>
<packaging>pom</packaging>
  1. 配置私库地址
    • 仓库地址分为正式版(releases repository)和预览版(snapshot repository)
    • id:在settings.xml中配置的server id
    • name:仓库名称
    • ur:对应的私库地址
<distributionManagement><repository><id>central</id><name>Maven Central</name><url>https://repo.maven.apache.org/maven2</url></repository>
</distributionManagement>
  1. 配置开发者信息、项目开源许可证、代码仓库地址
<developers><developer><id>000000000</id><name>xxxxxxx</name><email>000000000@qq.com</email></developer></developers><licenses><license><name>MIT License</name><url>https://opensource.org/licenses/MIT</url><distribution>repo</distribution></license></licenses><scm><connection>https://github.com/xx/xx.xx.xx.git</connection><url>https://github.com/xx/xx.xx.xx</url></scm>
  1. 配置打包插件

    • maven-source-plugin:源代码打包工具,中央仓库也会对源代码进行验证
    • maven-javadoc-plugin:javadoc文档打包工具,中央仓库会对javadoc经行验证,没有文档会验证失败
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>${maven-source-plugin.version}</version><inherited>true</inherited><executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution></executions><configuration><excludeResources>true</excludeResources><useDefaultExcludes>true</useDefaultExcludes></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>${maven-javadoc-plugin.version}</version><inherited>true</inherited><executions><execution><id>bundle-sources</id><phase>package</phase><goals><goal>jar</goal></goals></execution></executions><configuration><encoding>UTF-8</encoding><charset>UTF-8</charset><show>protected</show><notree>true</notree><failOnError>false</failOnError><doclint>none</doclint></configuration></plugin></plugins>
</build>
  1. 配置发布插件

    • central-publishing-maven-plugin:中央仓库发布插件
    • maven-deploy-plugin maven:maven发布插件,任何仓库都需要这个插件
    • maven-gpg-plugin:对发布的项目文件进行签名,中央仓库会对文件进行验签,GPG签名详见:https://central.sonatype.org/publish/requirements/gpg/
<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-deploy-plugin</artifactId><version>${maven-deploy-plugin.version}</version></plugin><plugin><groupId>org.sonatype.central</groupId><artifactId>central-publishing-maven-plugin</artifactId><version>${central-publishing-maven-plugin.version}</version><extensions>true</extensions><configuration><publishingServerId>central</publishingServerId><autoPublish>true</autoPublish><waitUntil>published</waitUntil></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>${maven-gpg-plugin.version}</version><executions><execution><id>sign-artifacts</id><phase>verify</phase><goals><goal>sign</goal></goals><configuration><keyname>288F5FE69C7B21AB</keyname><passphraseServerId>288F5FE69C7B21AB</passphraseServerId></configuration></execution></executions></plugin></plugins>
</build>

发布

  1. 运行发布命令
mvn deploy
  1. 等待maven central验证,如果发布状态不是published,那么就是发布失败,需要根据提示进行相应的更改
    在这里插入图片描述

FAQ

  1. Javadocs must be provided but not found in entries:因为中央仓库没找到Javadoc文档,所以需要打包Javadoc文档,java 1.8打包doc文档时,会报异常,建议提升至java11打包
  2. Illegal reflective access by lombok.javac.apt.LombokProcessor xxx:java11打包Lombok时,需要查看Lombok和java版本是否支持
http://www.lryc.cn/news/411160.html

相关文章:

  • 【Opencv】模糊
  • 函数式编程范式
  • 特征缩放的秘籍:sklearn中的数据标准化技术
  • hdfs文件系统
  • 基于STM32设计的个人健康检测仪(华为云IOT)(191)
  • 面试:CUDA Tiling 和 CPU tiling 技术详解
  • SQL语句中,`TRUNCATE` 和 `DELETE`的区别
  • 【Git】.gitignore全局配置与忽略匹配规则详解
  • 基于 YOLO V10 Fine-Tuning 训练自定义的目标检测模型
  • Java学习2
  • CSS、less、 Sass、
  • 北京大学:利用好不确定性,8B小模型也能超越GPT-4
  • ​​​​​​​哪些云服务商已通过了等保2.0合规性评估?​​​​​​​
  • PHP在线加密系统源码
  • OpenCV学习笔记 比较基于RANSAC、最小二乘算法的拟合
  • 前端JS特效第53集:带声音的烟花模拟绽放特效插件
  • 好展位,抢先订!2025浙江(玉环)机械展
  • Java面试八股之Spring如何解决循环依赖
  • 如何为 SQL Server 设置强密码以增强安全性?
  • C语言实现三子棋
  • 昇思25天学习打卡营第XX天|RNN实现情感分类
  • linux深度学习环境配置(cuda,pytorch)
  • SpringBoot教程(十九) | SpringBoot集成Slf4j日志门面
  • 科普文:深入理解ElasticSearch体系结构
  • 极限学习机(ELM)预测模型及其Python和MATLAB实现
  • 基于Python的哔哩哔哩国产动画排行数据分析系统
  • Java导出Excel给每一列设置不同样式示例
  • 2.1、matlab绘图汇总(图例、标题、坐标轴、线条格式、颜色和散点格式设置)
  • Datawhale AI夏令营 AI+逻辑推理 Task2总结
  • linux常使用的命令