Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vaadin 23.2.17 - Build for production fails #16577

Closed
giusdiluca opened this issue Apr 13, 2023 · 8 comments
Closed

Vaadin 23.2.17 - Build for production fails #16577

giusdiluca opened this issue Apr 13, 2023 · 8 comments

Comments

@giusdiluca
Copy link

Description of the bug

Hello,

my application runs fine in development mode, but when I try to run it in production mode (-Pproduction) build-frontend task fails.
Please look at the log attached.

vaadin_compile.log

Expected behavior

Build for production should not fail

Minimal reproducible example

mvn -Pproduction spring-boot:run

Versions

  • Vaadin / Flow version: 23.2.17
  • Java version: 11
  • OS version: RedHat 7
  • Browser version (if applicable):
  • Application Server (if applicable):
  • IDE (if applicable):
  • Maven: 3.8.4
@mcollovati mcollovati added this to Needs triage in OLD Vaadin Flow bugs & maintenance (Vaadin 10+) via automation Apr 13, 2023
@mcollovati
Copy link
Collaborator

Is there any chance that you compiled classes with a different JDK (e.g. 17) before running maven? Maybe the IDE compiled classes during development with Java 17? Or some dependency compiled with Java 17?

Does it fail even if you run a mvn -Pproduction clean spring-boot:run?

@giusdiluca
Copy link
Author

Hello Marco, no I didn't use JDK17 neither the IDE compile with Java 17 nor have any dependency compiled with that java verion.
I've just tried with the simple spring-boot:run as suggested and the errore is the same.

@mcollovati
Copy link
Collaborator

May I ask you to put a breakpoint in the forClass method of org.reflections.util.NameHelper class, at line 99 and then debug the maven process?

export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=y"
mvn -Pproduction spring-boot:run 

Line 99 should contain the following code

try { return classLoader.loadClass(type); }

When the breakpoint is reached, try to evaluate the expression classLoader.loadClass(type).
It should throw an exception, and then we can examine the stack trace, that unfortunately is suppressed int the catch block.

In addition, if you put another breakpoint at the end of the method (on the return null; instruction),
you can look at the typeName variable to check what class is causing the failure.

@mcollovati
Copy link
Collaborator

In the log I can see at lest a dependency to org.vaadin.olli:file-download-wrapper at version 7.0.0, that is for Vaadin 24 and compiled with JDK 17, and the add-on has a class annotated with @JsModule

org.vaadin.olli:file-download-wrapper:jar:7.0.0:compile

I don't know if this one is the cause, but you should change version, as you are on Vaadin 23.2

Based on the add-on page on directory, I suppose you should use version 4.0.0, as 5.0.0 is for Vaadin 23.3+ and 6.0.0 for Vaadin 24.

@giusdiluca
Copy link
Author

Thanks Marco, actually the addon was not used in the project, maybe added from someone else in the team to the pom.xml
During the development phase that did not caused issue, but while trying to build for production it crashed the build.
Removing the dependency from the pom.xml the issue was solved, thanks a lot.

OLD Vaadin Flow bugs & maintenance (Vaadin 10+) automation moved this from Needs triage to Closed Apr 13, 2023
@Artur-
Copy link
Member

Artur- commented Apr 14, 2023

As this seems to be an issue that pops up every now and then, is there anything we can do to improve the situation? For instance an error message that would hint at a Java version problem, or a missing --enable-preview flag as it was in another case

@mcollovati
Copy link
Collaborator

For this particular issue, a quick and dirty way to have additional information about the class compiled with an unsupported JDK may be to overwrite the loadClass for the URLClassLoader instance we provide to Reflections.

We can surround the super execution in a try/catch, log the offending class and propagate the exception.
Another solution would be to subclass Reflections and override the forClass method to intercept the exception, or just log the type name if the result of the super call is null.
However, modifying the exception handing is not ideal as it may require copy/paste the original method, and adding log messages may produce a verbose console output as forClass is used by many methods.
Perhaps the log message can be enabled and disabled with a flag, so we can enable it only on some code paths.

@diversit
Copy link

diversit commented Dec 4, 2023

Ran into this issue also this morning. Code compiled just fine. Only the vaadin-maven-plugin failed.
So I had to figure out how and where to add the missing --enable-preview flag, mentioned by @Artur- , since the compiler clearly had that setting already and the vaadin plugin has no way to add it.
So I figured that the Maven java process should be started with the --enable-preview setting.
There are, of course, multiple ways to do this.

  • setting JAVA_OPTS does not work
  • setting JAVA_TOOL_OPTIONS does work, but not easy to persist with the project.

Eventually settled on adding a .mvn/jvm.config with --enable-preview to the project. This gets picked up by Maven, see configurating Maven and is easy to check in Git so everyone has it.

With this we're able to use Java (21) preview features in Vaadin page classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants