Java服务_CheckStyle简介与使用实例
CheckStyle是一个帮助java开发人员遵守某些编写规范的工具,它能够自动化代码规范检查过程,从而使得开发人员从这项重要但是细致枯燥的工作中解脱出来。
checkstyle配置有两种配置方式,一种为安装插件,这种方式只能在本地运行代码是生效进行检查;第二种是添加maven依赖配置,这种在任意地方打包运行代码时都需要进行检查,推荐使用这种。Idea如何配置CheckStyle
1.添加checkstyle.xml文件
checkstyle.xml中有各种各样的检测规则,不通过则无法将代码成功打包,每个配置项对应的具体检查项目可以参考Checkstyle全局配置中style_template.xml创建方法:
1 |
|
2.在maven配置文件中添加checkstyle插件依赖
配置插件在项目编译、打包时进行检查:
1 | <build> |
3.check不通过case日志
1 | #16 [compiler 2/2] RUN --mount=type=secret,id=security-signature,target=/opt/local/sign/signer.jks,required=true,mode=0400,uid=1000,gid=1000 --mount=type=bind,from=git,src=/workspace/source,rw=true,target=/source --mount=type=bind,from=cache,src=/workspace/cache,rw=true,target=/root/.m2/repository/ cd /source/ && sh compile-1688468468.sh && artifact_path=`find /source/core/target -type f -maxdepth 1 -name "*.zip"|head -1`; if [ "$artifact_path" != "" ]; then mkdir -p /workspace/result-zip/ ;mv ${artifact_path} /workspace/result-zip//sv-arch-data-asset-drive-20230704.190108.673-9e7918d2.zip; else echo "zip file not found" && exit 1; fi && cp -r /root/.m2/repository/ /workspace/cache && echo 1688468468 |