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

升级OpenJDK 17与Gradle 7.6后GroovyFX项目注解类找不到问题求助

解决GroovyFX升级到OpenJDK17+Gradle7.6后FXBindableASTTransformation找不到的问题

升级GroovyFX项目到OpenJDK17与Gradle7.6后,出现以下错误:

Could not find class for Transformation Processor groovyx.javafx.beans.FXBindableASTTransformation declared by groovyx.javafx.beans.FXBindable

该错误在Java8环境下未出现,FXBindableASTTransformation是FXBindable注解关联的AST转换类。

核心原因

Java17的模块系统(JPMS)限制了反射与类加载权限,同时原项目依赖的Groovy版本可能不兼容Java17,Gradle7.x的编译逻辑也有调整,导致AST转换处理器无法被正确加载。

具体修复步骤

1. 升级Groovy版本到兼容Java17的版本

Groovy 3.x及以上开始支持Java11+,推荐使用Groovy4.x版本以更好适配Java17。修改项目根目录的build.gradle:

groovy {
    groovyVersion = '4.0.11' // 可根据最新稳定版本调整
}

2. 调整Gradle编译与运行的VM参数

Java17的模块系统会限制Groovy和JavaFX的反射访问,需要添加开放模块的参数。在build.gradle中添加:

// 为编译任务添加参数
tasks.withType(GroovyCompile) {
    options.compilerArgs += [
        '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
        '--add-opens', 'java.base/java.util=ALL-UNNAMED'
    ]
}

// 为运行任务添加参数
tasks.withType(JavaExec) {
    jvmArgs += [
        '--add-opens', 'java.base/java.lang=ALL-UNNAMED',
        '--add-opens', 'java.base/java.util=ALL-UNNAMED',
        '--add-modules', 'javafx.controls,javafx.fxml' // 确保加载JavaFX模块
    ]
}

3. 确保JavaFX依赖与Java版本匹配

升级JavaFX到17.x版本(与OpenJDK17对应),通过OpenJFX插件配置:

plugins {
    id 'org.openjfx.javafxplugin' version '0.0.13' // 或更高版本
}

javafx {
    version = '17.0.8'
    modules = ['javafx.controls', 'javafx.fxml'] // 根据项目需求添加模块
}

4. 验证AST转换类的编译与路径

  • 执行gradlew clean build,检查编译输出目录(如build/classes/groovy/main)下是否存在groovyx/javafx/beans/FXBindableASTTransformation.class文件
  • 确保FXBindable注解中指定的AST转换类全类名完全正确,无拼写错误

验证修复

完成上述修改后,重新执行以下命令验证:

gradlew clean build
gradlew runAccordionDemo

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 05:48:23