在操作这篇文章之前你需要做一些账号注册和提交申请前置操作, 前置操作我已经写了另一篇博客, 请移步 链接在此。

这篇接着讲如何使用gpg和和配置发布信息。 因为内容有点多, 所以最重要的打包和发布环节在第三篇博客中讲解,敬请期待。

各位读者,能否给我这个小博主一个关注点赞,谢谢。

整个教程分三篇博客讲解

  • 第一篇: 注册账号和提交申请
  • 第二篇: 安装gpg和配置pom.xml文件
  • 第三篇:打包上传发布(敬请期待)

目录

  • 申请账号
  • 提交申请
  • GPG签名使用
    • 下载安装 GPG
    • 生成秘钥
  • 项目的pom文件的配置
    • 基本信息
    • licenses 证书信息
    • scm软件配置管理插件
    • 配置开发者信息
    • distributionManagement配置仓库信息
    • build打包配置
    • profiles多环境配置
    • 完整pom文件
  • maven的setting.xml文件配置
  • maven打包项目

申请账号

链接在此

提交申请

链接在此

GPG签名使用

发布jar包需要使用gpg对你发布的包进行签名。 这段主要讲如何安装使用gpg。

GnuPG,简称 GPG,来自 http://www.gnupg.org,是 GPG 标准的一个免费实现。不管是 Linux 还是 Windows 平台,都可以使用。GPGneng 可以为文件生成签名、管理密匙以及验证签名。

下载安装 GPG

访问 http://www.gnupg.org/download,下载适合自己操作系统平台的安装程序。
mac系统推荐使用brew下载安装。
window系统可以下载gpg4win-2.3.3.exe。下载下来后正常安装即可。

生成秘钥


安装完成后, 桌面上会出现如图所示的图标,点开它。

如果是首次点开,图中红框部分会出现两个选项. 分别是生成新秘钥和导入秘钥。 我们选择新建秘钥

输入姓名和电子邮件,名称和邮件的组合不要和别人重复, 点击下一步。

会出现让你输入密码, 这个密码你可以自己设置, 设置好后要记住,后面会用到。 点击OK

出现下一步的三个选项, 我们先完成最重要的将公钥上传到
公共目录服务器

出现图中弹窗,表示上传成功了。 成功后的页面如下

图中就是显示的你生成的证书信息

项目的pom文件的配置

接下来我会分段讲解pom文件中的各个部分注意事项。并会在最后贴出完整的pom文件

基本信息

   <modelVersion>4.0.0</modelVersion><groupId>xyz.xiezc</groupId><artifactId>yao</artifactId><packaging>pom</packaging><version>1.0</version><name>yao</name><description>一个依赖注入的框架, 整合netty 提供类似springMvc的能力。 整合mybatis提供类似mybatis-spring的能力。</description><url>https://github.com/blanexie/Yao</url>

其中需要注意的是url填写你的项目github地址。 description简单描述下你的项目。

licenses 证书信息

    <licenses><license><name>Mulan Permissive Software License,Version 1</name><url>https://license.coscl.org.cn/MulanPSL/</url></license></licenses>

这里需要贴出你的开源证书的名称和证书的url。 我使用是木兰宽松许可。 所以贴出的是上面的地址,

  <licenses><license><name>Apache License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0</url></license></licenses>

Apache 协议 2.0
其他协议类似

scm软件配置管理插件

    <scm><connection>scm:git:https://github.com/blanexie/Yao.git</connection><developerConnection>scm:git:https://github.com/blanexie/Yao.git</developerConnection><url>git:https://github.com/blanexie/Yao.git</url></scm>

这里配置你的github的信息。 参考我的配置就行

scm 具体有何作用我也搞不懂, 希望知道的读者能在评论中告知我,谢谢。

配置开发者信息

    <developers><developer><name>blanexie</name><email>blanexie@qq.com</email></developer></developers>

这里就是配置开发者信息了, 如果有多个开发者,可以添加多个developer节点。

distributionManagement配置仓库信息

    <distributionManagement><snapshotRepository><id>snapshot</id><url>https://oss.sonatype.org/content/repositories/snapshots/</url></snapshotRepository><repository><id>release</id><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement>

这里就是配置上你之前的在发布申请的管理员会在评论中告知你的两个地址。这里需要注意两个地址不要弄混了。 同时需要记住你配置的两个id, 后面会使用到这两个id。

build打包配置

<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><configuration><attach>true</attach></configuration><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><target>${java.version}</target><source>${java.version}</source><encoding>${java.encoding}</encoding></configuration></plugin><!-- Javadoc --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>3.2.0</version><configuration><encoding>${java.encoding}</encoding><charset>${java.encoding}</charset><docencoding>${java.encoding}</docencoding></configuration><executions><execution><id>attach-javadocs</id><phase>package</phase><goals><goal>jar</goal></goals><configuration><additionalJOption>-Xdoclint:none</additionalJOption></configuration></execution></executions></plugin></plugins></build>
  • maven-source-plugin 插件必须配置,这个插件是将你的源码一起打包, maven仓库必须需要源码。 所以这个不能少。 具体可以参考我配置
  • maven-javadoc-plugin 插件必须, 这是安装你的代码中方法的注释生成javadoc文档的插件, 也是maven仓库必须的插件, 注意配置这个插件additionalJOption的值为true。 additionalJOption是告知maven忽略不规范的java注释。
  • maven-compiler-plugin 这个插件是配置编译的jdk版本信息等

profiles多环境配置

<profiles><profile><id>release</id><activation><jdk>11</jdk></activation><properties><additionalparam>-Xdoclint:none</additionalparam></properties><build><plugins><!-- Source --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><executions><execution><id>snapshot</id><phase>package</phase><goals><goal>jar-no-fork</goal></goals></execution><execution><id>release</id><phase>package</phase><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><!-- Gpg Signature --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.6</version><executions><execution><id>release</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.8</version><extensions>true</extensions><configuration><serverId>release</serverId><nexusUrl>https://oss.sonatype.org/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose></configuration></plugin></plugins></build></profile></profiles>

这中间也配置了build.。其中build中的插件有

  • maven-gpg-plugin 签名插件,这个插件会调用你本地电脑的gpg程序来签名代码。 到时候签名会有很多问题。后面部分会详细说明签名的问题。 这个也是maven仓库必须的插件。参考我的配置即可
  • nexus-staging-maven-plugin 这是帮助我们上传jar包到仓库的插件, 按照我的配置即可
  • maven-source-plugin 这个也是打包源码的插件,为何这里也有一个我也不知道。 希望知道的读者在评论告知。谢谢。

为何要这里定义一个release的profiles环境呢。 这个环境中maven-gpg-pluginnexus-staging-maven-plugin 插件都是只有发布包到maven仓库中才需要的,但是我们平时开发中, 并不是每次都是上传到公共仓库的,所以可以把上传需要的配置提取出来单独放在profile中是很好的处理方法, 平时就使用其他环境来打包。

上面已经分开把pom文件中需要注意的事项全部讲解完成了,下面会贴出完成版本。

完整pom文件

<?xml version="1.0" encoding="UTF-8"?>
<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.0</modelVersion><groupId>xyz.xiezc</groupId><artifactId>yao</artifactId><packaging>pom</packaging><version>1.0</version><name>yao</name><description>一个依赖注入的框架, 整合netty 提供类似springMvc的能力。 整合mybatis提供类似mybatis-spring的能力。</description><url>https://github.com/blanexie/Yao</url><properties><app.name>yao</app.name><maven.test.failure.ignore>false</maven.test.failure.ignore><maven.test.skip>false</maven.test.skip><java.version>11</java.version><java.encoding>UTF-8</java.encoding><project.build.sourceEncoding>${java.encoding}</project.build.sourceEncoding><maven.build.timestamp.format>yyyy-MM-dd_HH_mm</maven.build.timestamp.format><maven.compiler.source>${java.version}</maven.compiler.source><maven.compiler.target>${java.version}</maven.compiler.target><maven.compiler.compilerVersion>${java.version}</maven.compiler.compilerVersion></properties><modules><module>xioc</module><module>example</module><module>xweb</module><module>xorm</module></modules><dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>xyz.xiezc</groupId><artifactId>xweb</artifactId><version>${project.version}</version></dependency><dependency><groupId>xyz.xiezc</groupId><artifactId>xioc</artifactId><version>${project.version}</version></dependency><dependency><groupId>xyz.xiezc</groupId><artifactId>xorm</artifactId><version>${project.version}</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.3.0</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.12</version><scope>provided</scope></dependency><dependency><groupId>org.mybatis</groupId><artifactId>mybatis</artifactId><version>3.5.4</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.20</version></dependency><!-- https://mvnrepository.com/artifact/org.ow2.asm/asm --><dependency><groupId>org.ow2.asm</groupId><artifactId>asm</artifactId><version>8.0.1</version></dependency><dependency><groupId>cglib</groupId><artifactId>cglib</artifactId><version>3.3.0</version></dependency><dependency><groupId>io.netty</groupId><artifactId>netty-all</artifactId><version>4.1.49.Final</version></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><configuration><attach>true</attach></configuration><executions><execution><phase>compile</phase><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><target>${java.version}</target><source>${java.version}</source><encoding>${java.encoding}</encoding></configuration></plugin><!-- Javadoc --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>3.2.0</version><configuration><encoding>${java.encoding}</encoding><charset>${java.encoding}</charset><docencoding>${java.encoding}</docencoding></configuration><executions><execution><id>attach-javadocs</id><phase>package</phase><goals><goal>jar</goal></goals><configuration><additionalJOption>-Xdoclint:none</additionalJOption></configuration></execution></executions></plugin></plugins></build><licenses><license><name>Mulan Permissive Software License,Version 1</name><url>https://license.coscl.org.cn/MulanPSL/</url></license></licenses><scm><connection>scm:git:https://github.com/blanexie/Yao.git</connection><developerConnection>scm:git:https://github.com/blanexie/Yao.git</developerConnection><url>git:https://github.com/blanexie/Yao.git</url></scm><developers><developer><name>blanexie</name><email>blanexie@qq.com</email></developer></developers><distributionManagement><snapshotRepository><id>snapshot</id><url>https://oss.sonatype.org/content/repositories/snapshots/</url></snapshotRepository><repository><id>release</id><url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url></repository></distributionManagement><profiles><profile><id>release</id><activation><jdk>11</jdk></activation><properties><additionalparam>-Xdoclint:none</additionalparam></properties><build><plugins><!-- Source --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><executions><execution><id>snapshot</id><phase>package</phase><goals><goal>jar-no-fork</goal></goals></execution><execution><id>release</id><phase>package</phase><goals><goal>jar-no-fork</goal></goals></execution></executions></plugin><!-- Gpg Signature --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>1.6</version><executions><execution><id>release</id><phase>verify</phase><goals><goal>sign</goal></goals></execution></executions></plugin><plugin><groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.8</version><extensions>true</extensions><configuration><serverId>release</serverId><nexusUrl>https://oss.sonatype.org/</nexusUrl><autoReleaseAfterClose>true</autoReleaseAfterClose></configuration></plugin></plugins></build></profile></profiles></project>

maven的setting.xml文件配置

我使用的setting.xml配置文件在我用户目录的.m2目录下。注意要改到正确的maven使用的setting.xml文件才有效

 <servers><server> <id>snapshot</id> <username>xiezc</username> <password>***********(马赛克)</password> </server><server> <id>release</id> <username>xiezc</username> <password>***********(马赛克)</password> </server></servers>

在你的setting.xml文件中增加两个server节点。其中id节点就是你上面的pom文件的distributionManagement 节点的两个仓库的id。 注意这两个id一定要上面的pom文件中distributionManagement 节点配置的id一样
这两个节点的username就是你之前注册的账号的用户名, 密码是要你之前记住的注册时候的密码,如果忘记可以通过注册邮箱找回。 上一篇博客中我已经强调了要记住注册密码的。

maven打包项目

走完上面的流程,基本的前置工作已经完成了,下面就是激动人心的打包项目环节了。

发布包到maven公共仓库图文教程(2) --- gpg签名和pom.xml的配置等相关推荐

  1. 发布包到maven公共仓库图文教程(1) --- 注册账号和提交申请

    当你有个很好的想法, 写了一个开源的项目,想发布到maven公共仓库给别人用的时候, 你可能就需要这篇教程. 整个教程分三篇博客讲解 第一篇: 注册账号和提交申请 第二篇: 安装gpg和配置pom.x ...

  2. Java 中JAF、CORBA、JTA、JAXB、JAX-WS使用Maven的pom.xml文件配置

    本文主要介绍Java EE中已经弃用的模块,需要单独引用JAF(java.activation).CORBA(java.corba).JTA(java.transaction).JAXB(java.x ...

  3. maven中打包项目为war包的pom.xml配置

    maven中打包成war包的pom.xml配置 (1)完整配置:这个是使用servlet的完整配置,其他的类似. <project xmlns="http://maven.apache ...

  4. 构建dubbo分布式平台-maven构建ant-framework框架的pom.xml文件配置

    2019独角兽企业重金招聘Python工程师标准>>> 今天重点讲解的是ant-framework可信项目的构建过程. 其中ant-framework是ant分布式框架的基础核心框架 ...

  5. 你真的了解Maven pom.xml 的配置吗?【详解maven pom】

    Maven POM POM( Project Object Model,项目对象模型 ) 是 Maven 工程的基本工作单元,是一个XML文件,包含了项目的基本信息,用于描述项目如何构建,声明项目依赖 ...

  6. maven 3.6.3 下载与详细配置图文教程(基于win10系统)

    maven下载与配置 1. 下载maven 1.1 apache-maven官网下载链接 1.2 百度云资源下载 1.3 CSDN资源下载 2. 配置maven环境变量 3. 验证maven配置是否生 ...

  7. java创建出现module_Eclipse创建Maven多模块工程Module开发(图文教程)

    自己研究了下eclipse用maven多模块工程module开发,跟大家分享一下! 功能模块来分module,跟java的package类似,一般是按照的功能模块分module,比如:sso/cas/ ...

  8. Spring Boot 2.0 的配置详解(图文教程)

    本文来自作者 泥瓦匠 @ bysocket.com 在 GitChat 上分享 「Spring Boot 2.0 的配置详解(图文教程)」 编辑 | 哈比 Spring Boot 配置,包括自动配置和 ...

  9. Maven 最全教程,看了必懂,99% 的人都收藏了!

    来源:cnblogs.com/hzg110/p/6936101.html 一.为什么使用Maven这样的构建工具[why] 二.maven是什么[what] 三.安装maven 四.第一个maven ...

最新文章

  1. day23:shell基础介绍 alias及重定向
  2. k8s 下线node正确处理姿势
  3. 不看不知道 Vista回收站暗藏的大秘密
  4. python有证书考吗-学python需要考证吗?
  5. python读csv-python读写csv文件
  6. 编程实现将rdd转换为dataframe:源文件内容如下(_大数据 什么是RDD?可以干什么?为什么要有RDD?...
  7. 幸福指数测试软件,测试你和ta的幸福指数能不能爆表
  8. java马克思手稿_java 循环嵌套解决一元,二元,三元方程(增长率,鸡兔同笼,马克思手稿)...
  9. $.post 中文乱码 php,如何解决jquery $.post 乱码问题
  10. php生成网页桌面快捷方式
  11. [译] Bulma: 2018年你应该关注的CSS框架
  12. 集合类接口和类层次关系图
  13. 修改sqlserver编码为utf8_修改Matlab默认编码格式为UTF-8
  14. VC通用控件自适应屏幕类
  15. 廖雪峰全套Java教程下载(稀有资源)
  16. ABAQUS2021界面改成中文
  17. 基于PC端的爬取公众号历史文章
  18. 基于iTextSharp(C#)创建PDF文件
  19. 图片轮播banner实现
  20. P2002 消息扩散(图论 Tarjan缩点)

热门文章

  1. 计算机中的用户拒绝访问权限,win7系统打开c盘提示“拒绝访问”的处理方法
  2. Git 解决速度太慢问题(电信宽带)
  3. 4.Wireshark下载安装和使用教程
  4. 华为Matebook X 成功安装黑苹果
  5. JAVA基础 装箱类型
  6. 面试华为软件测试岗,收到offer后我却毫不犹豫拒绝了....
  7. 8255交通灯实验的微型计算机,微机原理实验四实验报告8255控制交通灯实验
  8. html新闻标题太长,关于seo优化新闻标题的撰写注意事项
  9. 论文阅读笔记《DEAM: Dialogue Coherence Evaluation using AMR-based SemanticManipulations》
  10. Verilog 代码优化技巧