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,示例:
非模块化项目可在Maven构建配置中添加JVM参数:opens com.yourpackage to com.vaadin, org.reflections;--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
相关产品推荐
相关产品推荐

