用途:诊断并修复 Apache Doris FE 模块的 Java 代码风格问题,依据项目自带的 Checkstyle 配置执行。
主要能力:运行 Checkstyle 检查、解读违规信息、修复常见违规并复验。Checkstyle 已集成到 Maven 构建,在 mvn validate 阶段自动运行。仅检查风格(不完整编译)可执行:cd fe && mvn checkstyle:check -pl fe-core;也可作为正常构建的一部分:./build.sh --fe -j${DORIS_PARALLELISM}。失败时构建会报出文件、行号与违反的规则。
常见违规与修复:RegexpHeader 需在文件顶部添加/修正 Apache License 头;UnusedImports 删除未使用导入;LineLength(超过 120 字符)需断行;IllegalImport(shaded 类)改用非 shaded 等价类(见 import-control.xml);FileTabCharacter 用空格替换制表符;NewlineAtEndOfFile 确保文件以换行结尾;MergeConflictMarker 解决 git 合并冲突。修复后重新运行上述 checkstyle 命令确认。
关键配置:fe/check/checkstyle/checkstyle.xml 主规则(许可证头、行长 120、编码、导入);suppressions.xml 规则排除(测试文件、nereids、大文件);import-control.xml 导入限制(禁用 shaded 类、旧日志 API、nereids 中禁用 Lombok);checkstyle-apache-header.txt 为 Apache License 2.0 头模板;build-support/IntelliJ-code-format.xml 为 IntelliJ 格式化方案(120 列、导入组织)。
导入限制要点:不得直接使用 org.apache.doris.thirdparty.*;不得使用 org.apache.commons.logging 或 java.util.logging;不得使用 SimpleDateFormat,改用 java.time API;org.apache.doris.nereids 包中禁用 lombok。
排除范围:生成的 Thrift 代码(/apache/doris/thrift//)与生成的 Parquet 代码(/apache/parquet//)不参与 checkstyle。
限制与排错:构建在 validate 阶段失败时,运行 mvn checkstyle:check -pl fe-core 查看具体违规;找不到配置需确保在 fe/ 目录下运行;IntelliJ 格式化不一致时,通过 Settings → Editor → Code Style 导入 build-support/IntelliJ-code-format.xml。