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

Vaadin 23 -Pproduction构建失败求助

Vaadin 23 生产模式构建失败排查方案

问题概述

技术栈升级至Java 17、Maven 3、Spring 2.7/core 5.3及Vaadin 23后,项目可正常在开发模式运行,但执行mvn clean package -Pproduction构建时失败,核心报错如下:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  33.260 s
[INFO] Finished at: 2022-08-31T11:35:42-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.vaadin:flow-maven-plugin:23.1.6:build-frontend (default) on project template-module-app: Could not execute build-frontend goal: Error occured during goal execution: Cannot invoke "java.lang.Class.isInterface()" because the return value of "org.reflections.Reflections.forClass(String, java.lang.ClassLoader[])" is nullPlease run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.vaadin:flow-maven-plugin:23.1.6:build-frontend (default) on project template-module-app: Could not execute build-frontend goal
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:375)

排查步骤

  • 获取完整错误栈:执行mvn clean package -Pproduction -e,通过完整栈追踪定位具体找不到的类,这是锁定问题根源的核心步骤。
  • 适配Java 17反射权限:Java 17模块化系统会限制反射访问,若为模块化项目,需在module-info.java中开放相关包给Vaadin,示例:
    opens com.yourpackage to com.vaadin, org.reflections;
    
    非模块化项目可在Maven构建配置中添加JVM参数:--add-opens java.base/java.lang=ALL-UNNAMED。
  • 校验插件与依赖版本一致性:确保flow-maven-plugin版本(当前为23.1.6)与项目中Vaadin核心依赖版本完全匹配,避免版本不兼容引发扫描异常。
  • 清理构建缓存:删除target目录、frontend/node_modules目录及项目根目录下的.vaadin缓存文件夹,彻底清理后重新执行构建。
  • 排查依赖冲突:执行mvn dependency:tree检查是否存在org.reflections:reflections版本冲突,Vaadin 23依赖特定版本的Reflections,需排除其他依赖引入的冲突版本。
  • 检查Spring生产配置:确认Spring配置中已禁用DevTools(生产模式下DevTools会干扰构建),同时校验@VaadinServletConfiguration的productionMode参数是否设为true。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 17:48:29