You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行gradle clean build时Checkstyle报NoClassDefFoundError错误求助

问题描述

执行gradle clean build命令时,Task :checkstyleMain环节抛出NoClassDefFoundError异常。移除build.gradle中的checkstyle插件及相关配置后,构建可正常完成。尝试手动添加commons-collections:3.2.2和commons-beanutils:1.9.4作为项目依赖,问题仍未解决。

错误栈信息

java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap
    at org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:963)
    at org.apache.commons.beanutils.BeanUtilsBean.copyProperty(BeanUtilsBean.java:391)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.tryCopyProperty(AutomaticBean.java:217)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.contextualize(AutomaticBean.java:249)
    at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:455)
    at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:186)

Checkstyle依赖树(gradle dependencies输出)

com.puppycrawl.tools:checkstyle:10.0
+---info.picocli
+---org.antlr
+---commons-beanutils
+---com.google.guava
+---org.reflections
\---net.sf.saxon

build.gradle相关代码片段

plugins {
    id 'checkstyle'
}

group = 'com.example.project'
version = '0.1'
sourceCompatibility = '11'

configurations {
   compileOnly {
      extendsFrom annotationProcessor
   }
}

repositories {
 ...
}

dependencies {
 ...
}

checkstyle {
   configFile file("checkstyle.yml")
   toolVersion '10.0'
   maxErrors 0
   maxWarnings 0
}

解决方案

1. 为Checkstyle插件类路径强制引入依赖

项目依赖不会自动注入到Checkstyle插件的类加载上下文,需要直接给Checkstyle的配置指定依赖:

checkstyle {
   configFile file("checkstyle.yml")
   toolVersion '10.0'
   maxErrors 0
   maxWarnings 0
}

configurations.checkstyle {
    resolutionStrategy {
        force 'commons-collections:commons-collections:3.2.2'
    }
}

2. 升级Checkstyle版本

Checkstyle 10.x后续版本已修复该依赖兼容问题,建议升级到最新稳定版(如10.17.0):

checkstyle {
   configFile file("checkstyle.yml")
   toolVersion '10.17.0'
   maxErrors 0
   maxWarnings 0
}

3. 验证配置文件兼容性

确认checkstyle.yml与Checkstyle 10.0版本兼容,旧配置项可能触发异常路径。若配置从旧版本迁移,需对照官方文档更新配置项。

内容的提问来源于stack exchange,提问作者Fran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 04:10:28