KCloud-Platform-IoT KCloud-Platform-IoT
首页
  • 开发手册

    • 组件【ai】
    • 组件【algorithm】
    • 组件【banner】
    • 组件【clickhouse】
    • 组件【core】
    • 组件【bom】
    • 组件【cors】
    • 组件【domain】
    • 组件【crypto】
    • 组件【data-cache】
    • 组件【dubbo】
    • 组件【elasticsearch】
    • 组件【excel】
    • 组件【extension】
    • 组件【flink】
    • 组件【grpc】
    • 组件【i18n】
    • 组件【idempotent】
    • 组件【influxdb】
    • 组件【kafka】
    • 组件【log】
    • 组件【lock】
    • 组件【mail】
    • 组件【log4j2】
    • 组件【mqtt】
    • 组件【mongodb】
    • 组件【mybatis-plus】
    • 组件【nacos】
    • 组件【netty】
    • 组件【openapi-doc】
    • 组件【openfeign】
    • 组件【oss】
    • 组件【prometheus】
    • 组件【rabbitmq】
    • 组件【rate-limiter】
    • 组件【reactor】
    • 组件【redis】
    • 组件【rocketmq】
    • 组件【ruleengine】
    • 组件【secret】
    • 组件【security】
    • 组件【sensitive】
    • 组件【sentinel】
    • 组件【sms】
    • 组件【snail-job】
    • 组件【spark】
    • 组件【starrocks】
    • 组件【statemachine】
    • 组件【storage】
    • 组件【tdengine】
    • 组件【tenant】
    • 组件【test】
    • 组件【trace】
    • 组件【xss】
    • 组件【shardingsphere】
  • 环境搭建

    • Centos7安装Mysql 8.0.33
    • Centos7安装Redis 7.0.11
    • Centos7安装RocketMQ 5.1.1
    • Centos7安装Jdk 17.0.7
    • Centos7安装Docker 23.0.6
    • Centos7安装Elasticsearch 8.6.2
    • Docker安装RabbitMQ 3.12.2
    • Docker安装Postgresql 16.1
    • Ubuntu20.04安装Docker
    • Ubuntu20.04忘记密码或指纹错误
  • 常用命令

    • Centos7常用命令
    • Centos7常用命令
  • 快速上手

    • 项目启动【dev环境】
    • 项目启动【test环境】
    • 项目启动【prod环境】
    • 更新日志
  • 前端指南

    • 前端启动
  • 后端指南

    • COLA代码规范
    • SSL证书
    • 一键修改项目模块
    • 一键生成项目骨架
    • 一键修改项目版本号
    • 一键跳过测试用例
    • 一键生成后端COLA代码
    • 分布式链路跟踪之ELK日志
    • 一键检查代码规范
    • 动态路由
  • 项目部署

    • 项目部署之镜像打包与推送
  • 其他

    • Java如何快速转Go
    • Go快速开发API
    • Vue快速开发Api
    • React快速开发Api
  • 文章

    • 物联网之对接MQTT最佳实践
    • 物联网之使用Vertx实现MQTT-Server最佳实践【响应式】
    • vue3+lime-echart各种图表使用【懒人专用,建议收藏】
    • 物联网之使用Vertx实现TCP最佳实践【响应式】
    • 物联网之使用Vertx实现HTTPWebSocket最佳实践【响应式】
    • 物联网之使用Vertx实现UDP最佳实践【响应式】
  • 儒学

    • 儒学摘抄(一)
  • 禅语

    • 禅语摘抄(一)
  • 诗词

    • 诗词摘抄(一)
  • 道法

    • 道法摘抄(一)
  • 养生

    • 养生摘抄(一)
  • 读后感

    • 读《强者,都是含泪奔跑的人》读后感
  • 修行

    • 修身/养生/情感
  • 觉悟

    • 觉悟日记(一)
赞助
项目课程 (opens new window)
GitHub (opens new window)
首页
  • 开发手册

    • 组件【ai】
    • 组件【algorithm】
    • 组件【banner】
    • 组件【clickhouse】
    • 组件【core】
    • 组件【bom】
    • 组件【cors】
    • 组件【domain】
    • 组件【crypto】
    • 组件【data-cache】
    • 组件【dubbo】
    • 组件【elasticsearch】
    • 组件【excel】
    • 组件【extension】
    • 组件【flink】
    • 组件【grpc】
    • 组件【i18n】
    • 组件【idempotent】
    • 组件【influxdb】
    • 组件【kafka】
    • 组件【log】
    • 组件【lock】
    • 组件【mail】
    • 组件【log4j2】
    • 组件【mqtt】
    • 组件【mongodb】
    • 组件【mybatis-plus】
    • 组件【nacos】
    • 组件【netty】
    • 组件【openapi-doc】
    • 组件【openfeign】
    • 组件【oss】
    • 组件【prometheus】
    • 组件【rabbitmq】
    • 组件【rate-limiter】
    • 组件【reactor】
    • 组件【redis】
    • 组件【rocketmq】
    • 组件【ruleengine】
    • 组件【secret】
    • 组件【security】
    • 组件【sensitive】
    • 组件【sentinel】
    • 组件【sms】
    • 组件【snail-job】
    • 组件【spark】
    • 组件【starrocks】
    • 组件【statemachine】
    • 组件【storage】
    • 组件【tdengine】
    • 组件【tenant】
    • 组件【test】
    • 组件【trace】
    • 组件【xss】
    • 组件【shardingsphere】
  • 环境搭建

    • Centos7安装Mysql 8.0.33
    • Centos7安装Redis 7.0.11
    • Centos7安装RocketMQ 5.1.1
    • Centos7安装Jdk 17.0.7
    • Centos7安装Docker 23.0.6
    • Centos7安装Elasticsearch 8.6.2
    • Docker安装RabbitMQ 3.12.2
    • Docker安装Postgresql 16.1
    • Ubuntu20.04安装Docker
    • Ubuntu20.04忘记密码或指纹错误
  • 常用命令

    • Centos7常用命令
    • Centos7常用命令
  • 快速上手

    • 项目启动【dev环境】
    • 项目启动【test环境】
    • 项目启动【prod环境】
    • 更新日志
  • 前端指南

    • 前端启动
  • 后端指南

    • COLA代码规范
    • SSL证书
    • 一键修改项目模块
    • 一键生成项目骨架
    • 一键修改项目版本号
    • 一键跳过测试用例
    • 一键生成后端COLA代码
    • 分布式链路跟踪之ELK日志
    • 一键检查代码规范
    • 动态路由
  • 项目部署

    • 项目部署之镜像打包与推送
  • 其他

    • Java如何快速转Go
    • Go快速开发API
    • Vue快速开发Api
    • React快速开发Api
  • 文章

    • 物联网之对接MQTT最佳实践
    • 物联网之使用Vertx实现MQTT-Server最佳实践【响应式】
    • vue3+lime-echart各种图表使用【懒人专用,建议收藏】
    • 物联网之使用Vertx实现TCP最佳实践【响应式】
    • 物联网之使用Vertx实现HTTPWebSocket最佳实践【响应式】
    • 物联网之使用Vertx实现UDP最佳实践【响应式】
  • 儒学

    • 儒学摘抄(一)
  • 禅语

    • 禅语摘抄(一)
  • 诗词

    • 诗词摘抄(一)
  • 道法

    • 道法摘抄(一)
  • 养生

    • 养生摘抄(一)
  • 读后感

    • 读《强者,都是含泪奔跑的人》读后感
  • 修行

    • 修身/养生/情感
  • 觉悟

    • 觉悟日记(一)
赞助
项目课程 (opens new window)
GitHub (opens new window)
  • 开发手册

    • 组件【ai】
    • 组件【algorithm】
    • 组件【banner】
    • 组件【clickhouse】
    • 组件【core】
    • 组件【bom】
    • 组件【cors】
    • 组件【domain】
    • 组件【crypto】
    • 组件【data-cache】
    • 组件【dubbo】
    • 组件【elasticsearch】
    • 组件【excel】
    • 组件【extension】
    • 组件【flink】
    • 组件【grpc】
    • 组件【i18n】
    • 组件【idempotent】
    • 组件【influxdb】
    • 组件【kafka】
    • 组件【log】
    • 组件【lock】
    • 组件【mail】
    • 组件【log4j2】
    • 组件【mqtt】
    • 组件【mongodb】
    • 组件【mybatis-plus】
    • 组件【nacos】
    • 组件【netty】
    • 组件【openapi-doc】
    • 组件【openfeign】
    • 组件【oss】
    • 组件【prometheus】
    • 组件【rabbitmq】
    • 组件【rate-limiter】
    • 组件【reactor】
    • 组件【redis】
    • 组件【rocketmq】
    • 组件【ruleengine】
    • 组件【secret】
    • 组件【security】
    • 组件【sensitive】
    • 组件【sentinel】
    • 组件【sms】
    • 组件【snail-job】
    • 组件【spark】
    • 组件【starrocks】
    • 组件【statemachine】
    • 组件【storage】
    • 组件【tdengine】
    • 组件【tenant】
    • 组件【test】
    • 组件【trace】
    • 组件【xss】
    • 组件【shardingsphere】
  • 环境搭建

    • Centos7安装Mysql 8.0.33
    • Centos7安装Redis 7.0.11
    • Centos7安装RocketMQ 5.1.1
    • Centos7安装Jdk 17.0.7
    • Centos7安装Docker 23.0.6
    • Docker安装RabbitMQ 3.12.2
    • Centos7安装Elasticsearch 8.6.2
    • Docker安装Postgresql 16.1
    • Ubuntu20.04安装Docker
    • Ubuntu20.04忘记密码或指纹错误
  • 常用命令

    • Centos7常用命令
    • Docker常用命令
  • 快速上手

    • 项目启动【dev环境】
    • 项目启动【test环境】
    • 项目启动【prod环境】
    • 更新日志
  • 前端指南

    • 前端启动
  • 后端指南

    • COLA代码规范
    • SSL证书
    • 一键修改项目模块
    • 一键生成项目骨架
    • 一键修改项目版本号
    • 一键跳过测试用例
    • 一键生成后端COLA代码
    • 分布式链路跟踪之ELK日志
    • 一键检查代码规范
      • 动态路由
      • OAuth2.1流程
    • 项目部署

      • 项目部署之镜像打包与推送
    • 其他

      • Java如何快速转Go
      • Go快速开发API
      • Vue快速开发Api
      • React快速开发Api
    • 文章

      • 物联网之对接MQTT最佳实践
      • 物联网之使用Vertx实现MQTT-Server最佳实践【响应式】
      • vue3+lime-echart各种图表使用【懒人专用,建议收藏】
      • 物联网之使用Vertx实现TCP最佳实践【响应式】
      • 物联网之使用Vertx实现HTTPWebSocket最佳实践【响应式】
      • 物联网之使用Vertx实现UDP最佳实践【响应式】
    • 指南
    • 后端指南
    KCloud-Platform-IoT
    2024-09-02
    目录

    一键检查代码规范

    你好呀,我的老朋友!我是老寇,欢迎来到老寇云平台!

    话不多说,讲一讲一键检查代码规范!

    # 引入插件

    
    <plugins>
    	<plugin>
    		<groupId>org.apache.maven.plugins</groupId>
    		<artifactId>maven-checkstyle-plugin</artifactId>
    		<version>3.5.0</version>
    		<configuration>
    			<!-- 配置文件路径 -->
    			<configLocation>checkstyle/checkstyle.xml</configLocation>
    			<!-- true表示在命令行或控制台输出检查结果,否则结果不会直接在控制台显示 -->
    			<consoleOutput>true</consoleOutput>
    			<!-- true表示检查到错误,则整个构建过程失败 -->
    			<failsOnError>true</failsOnError>
    			<!-- 是否直接构造失败,true只要任何一个代码规范不通过,从而直接构建失败,false代码检查不通过,不会导致构建失败,但会报告违规情况 -->
    			<failOnViolation>true</failOnViolation>
    			<!-- 是否包含测试代码目录,true包含,false不包含,只检查主目录代码 -->
    			<includeTestSourceDirectory>true</includeTestSourceDirectory>
    			<!-- 是否跳过代码规范检查,true跳过,false不跳过 -->
    			<skip>false</skip>
    			<!-- checkstyle报告是否包含代码引用链接,false不包含,true包含 -->
    			<linkXRef>false</linkXRef>
    		</configuration>
    		<executions>
    			<!-- 执行mvn install启动代码规范扫描 -->
    			<execution>
    				<id>install</id>
    				<phase>install</phase>
    				<goals>
    					<goal>checkstyle</goal>
    				</goals>
    			</execution>
    		</executions>
    	</plugin>
    </plugins>
    

    # checkstyle使用

    checkstyle官方地址 (opens new window)

    创建checkstyle.xml

    注意:目前,就做了协议头、未使用的依赖和匹配句子末尾的格式校验,都有注释,请自行阅读,而且链接也放在上面,自行对照即可
    <?xml version="1.0"?>
    <!DOCTYPE module PUBLIC
    	"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
    	"https://www.puppycrawl.com/dtds/configuration_1_3.dtd">
    <module name="Checker">
    
    	<!-- https://checkstyle.sourceforge.io/property_types.html -->
    
    	<!-- 字符集 -->
    	<property name="charset" value="UTF-8"/>
    
    	<!-- 检查级别 -->
    	<property name="severity" value="error"/>
    
    	<!-- 抑制过滤器 https://checkstyle.sourceforge.io/filters/suppressionfilter.html#SuppressionFilter -->
    	<module name="SuppressionFilter">
    		<property name="file" value="checkstyle/checkstyle-suppressions.xml"/>
    		<property name="optional" value="false"/>
    	</module>
    
    	<!-- 检查协议头 https://checkstyle.sourceforge.io/checks/header/regexpheader.html -->
    	<module name="RegexpHeader">
    		<property name="headerFile" value="checkstyle/checkstyle-header.txt"/>
    		<property name="fileExtensions" value="java"/>
    	</module>
    
    	<module name="TreeWalker">
    
    		<!-- 匹配句子末尾的格式 https://checkstyle.sourceforge.io/checks/javadoc/javadocstyle.html#JavadocStyle -->
    		<module name="JavadocStyleCheck">
    			<property name="endOfSentenceFormat" value="([.?!。?!][ \t\n\r\f&lt;])|([.?!。?!]$)"/>
    		</module>
    
    		<!-- 排除导入的未使用的依赖 https://checkstyle.sourceforge.io/checks/imports/unusedimports.html -->
    		<module name="UnusedImports">
    			<!-- true忽略文档依赖,false不忽略文档依赖 -->
    			<property name="processJavadoc" value="true"/>
    		</module>
    
    	</module>
    
    </module>
    
    

    注意:协议头验证,需要创建checkstyle-header.txt

    ^\Q/*\E$
    ^\Q * Copyright (c) \E20\d\d\-20\d\d\Q KCloud-Platform-IoT Author or Authors. All Rights Reserved.\E$
    ^\Q *\E$
    ^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$
    ^\Q * you may not use this file except in compliance with the License.\E$
    ^\Q * You may obtain a copy of the License at\E$
    ^\Q *\E$
    ^\Q *   http://www.apache.org/licenses/LICENSE-2.0\E$
    ^\Q *\E$
    ^\Q * Unless required by applicable law or agreed to in writing, software\E$
    ^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$
    ^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$
    ^\Q * See the License for the specific language governing permissions and\E$
    ^\Q * limitations under the License.\E$
    ^\Q *\E$
    ^\Q */\E$
    ^$
    ^.*$
    

    注意:checkstyle-suppressions.xml可以用来排除不扫描的文件,比如排除mapstruct生成的代码

    <!DOCTYPE suppressions PUBLIC
    	"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
    	"https://checkstyle.org/dtds/suppressions_1_2.dtd">
    <suppressions>
    	<!-- https://checkstyle.sourceforge.io/filters/suppressionfilter.html -->
    	<suppress files="[\\/]org[\\/]laokou[\\/]admin[\\/]convertor[\\/].*ConvertorImpl.java" checks=".*"/>
    	<suppress files="[\\/]org[\\/]laokou[\\/]auth[\\/]convertor[\\/].*ConvertorImpl.java" checks=".*"/>
    </suppressions>
    

    # 使用

    mvn clean install -P test
    

    我是老寇,我们下次再见啦!

    上次更新: 5/21/2025, 5:17:33 PM
    分布式链路跟踪之ELK日志
    动态路由

    ← 分布式链路跟踪之ELK日志 动态路由→

    Theme by Vdoing | Copyright © 2022-2025 laokou | Apache 2.0 License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式