发布项目到Maven中央仓库,封装了星球项目的全局异常处理器,错误码,和响应类以及Knife4j接口文档

前几天有个突发奇想:每次创建Web项目都要重新写或者复制全局异常处理器,错误码,和响应类等等,很麻烦,作为新时代的我自然不愿意每次都做这么繁琐的事情。干脆直接搞一个starter,说干就干,然后就有了这个教程也是踩了一些坑,下面是我能够跑成功的示例,希望能够帮助到大家。然后借用鱼聪明起了名字和简介,甚至README文档都是ai生成的。

目前在Github开源了

项目地址:qimu666/EazyWeb: 快速构建Web应用,整合Knife4j接口文档,自定义错误码和全局异常处理器,一切尽在EazyWeb。 (github.com)

大家也可以使用我的封装的starter来开发自己的项目,只需要在项目中引用坐标,然后配置匹配策略和扫描包路径就可以使用了

<dependency>
<groupId>icu.qimuu</groupId>
<artifactId>EazyWeb</artifactId>
<version>0.0.1</version>
</dependency>

示例配置:

简略配置:

knife4j:
config:
scan-path: com.qimuu.demo.controller
spring:
mvc:
path match:
matching-strategy: ant_path_matcher

全量配置:

knife4j:
config:
name: Author
email: xxx
version: API version
title: API document
description: API document description
scan-path: com.qimuu.demo.controller
spring:
mvc:
path match:
matching-strategy: ant_path_matcher


注册账号和生成GPG生成密钥教程

主要看注册账号和生成GPG密匙部分就行了,出现问题可以先在这两个地方找

gpg加密发布jar包到maven中央仓库详细过程以及踩的坑_佛系猿秦大昊的博客-CSDN博客

来开源吧!发布开源组件到 MavenCentral 仓库超详细攻略 - 掘金 (juejin.cn)


1. 修改Maven配置文件


全局配置文件添加

<server>
<id>sonatype-qimu</id>
<username>sonatype账号</username>
<password>密码</password>
</server>


2. 修改项目pom,xml


在Maven项目的pom.xml中添加licenses、developers、scm、profiles、plugins、distributionManagement等内容,示例:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>2.7.0</version>
       <relativePath/> <!-- lookup parent from repository -->
   </parent>
   <groupId>icu.qimuu</groupId>
   <artifactId>EazyWeb</artifactId>
   <version>0.0.1</version>
   <name>EazyWeb</name>
   <description>EazyWeb</description>
   <properties>
       <maven.compiler.source>1.8</maven.compiler.source>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   <licenses>
       <license>
           <name>The Apache Software License, Version 2.0</name>
           <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
       </license>
   </licenses>
   <!-- 根据自己实际情况填写 -->
   <developers>
       <developer>
           <name>qimu</name>
           <email>2483482026@qq.com</email>
       </developer>
   </developers>
   <!-- 与申请issue时填写的SCM保持一致 -->
   <scm>
       <connection>https://github.com/qimu666/EazyWeb.git</connection>
       <developerConnection>https://github.com/qimu666/EazyWeb.git</developerConnection>
       <url>https://github.com/qimu666/EazyWeb</url>
   </scm>
   <profiles>
       <profile>
           <!-- 这个id就是打包时的 -P 参数 -->
           <id>release</id>
           <build>
               <plugins>
                   <!-- Source插件-->
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-source-plugin</artifactId>
                       <version>2.2.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.9.1</version>
                       <executions>
                           <execution>
                               <phase>package</phase>
                               <goals>
                                   <goal>jar</goal>
                               </goals>
                               <!-- -Xdoclint:none 是为了避免生成apidoc的时候检查过于严格而报错-->
                               <configuration>
                                   <additionalparam>-Xdoclint:none</additionalparam>
                               </configuration>
                           </execution>
                       </executions>
                   </plugin>
                   <!-- GPG加密插件 -->
                   <plugin>
                       <groupId>org.apache.maven.plugins</groupId>
                       <artifactId>maven-gpg-plugin</artifactId>
                       <version>1.6</version>
                       <executions>
                           <execution>
                               <phase>verify</phase>
                               <goals>
                                   <goal>sign</goal>
                               </goals>
                           </execution>
                       </executions>
                   </plugin>
               </plugins>
           </build>
           <!-- snapshotRepository与repository的id应与setting.xml中添加的server的id一致 -->
           <distributionManagement>
               <snapshotRepository>
                   <id>sonatype-qimu</id>
                   <url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
               </snapshotRepository>
               <repository>
                   <id>sonatype-qimu</id>
                   <url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
               </repository>
           </distributionManagement>
       </profile>
   </profiles>
   <dependencies>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-web</artifactId>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-configuration-processor</artifactId>
           <optional>true</optional>
       </dependency>
       <dependency>
           <groupId>com.github.xiaoymin</groupId>
           <artifactId>knife4j-spring-boot-starter</artifactId>
           <version>3.0.3</version>
       </dependency>
       <dependency>
           <groupId>org.projectlombok</groupId>
           <artifactId>lombok</artifactId>
           <optional>true</optional>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-test</artifactId>
           <scope>test</scope>
       </dependency>
   </dependencies>
</project>


3. 控制台执行命令


mvn clean deploy -P release


0个评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
柒木
下载 APP