Multi module Gradle Hilla and Java 21

Hi,

I am trying to compile a Hilla project with multi modules in Gradle. It works for dev with Java 17 and 21 and it works with Java 17 when I compile for production. When I try to compile it in production mode and Java 21 I get the follow error. Has anyone had this problem as well?

./gradlew -Philla.productionMode=true clean build

Configure project :
21.0.2 (Oracle Corporation 21.0.2+13-58)

Task :vaadinBuildFrontend FAILED
Visiting class jdk.internal.vm.annotation.IntrinsicCandidate failed with Unsupported class file major version 65.
This might be a broken class in the project.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:vaadinBuildFrontend’.

com.vaadin.flow.server.ExecutionFailedException: Error occured during goal execution: Unsupported class file major version 65Please run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace.

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use ‘–warning-mode all’ to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to Command-Line Interface Reference in the Gradle documentation.

BUILD FAILED in 11s
30 actionable tasks: 23 executed, 7 up-to-date

Hi Thiago.

I’ve found this stackoverflow post that might be related, did you try setting sourceCompatibility and targetCompatibility to 21 in your build.gradle file?

Regards.

Hi @mmlopez . Thanks for the feedback! I saw that post too. I specified it in the root build.gradle and in a plugin inside buildSrc, which all modules include. That did not work. Perhaps I should specify in all individual build.gradle modules?

Yes, or maybe in just the modules that are failing. That can give us an idea of what could be going on.

I tried to add:

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

to all build.gradle files in the project, but it did not work.

One extra piece of information.

I am using sdkman to manage the SDKs.

default is Java 21
In use Java 21
In Intellij, project and gradle SDKs are pointing to version 21 as well

I was reviewing the so post that I shared with you earlier, and in there they are also mentioning about:

  • JAVA_HOME defaulting to the one cached in .gradle Folder in user directory even after changing the system variables to point to another JDK. Deleting the .gradle Folder fixed that issue for them, did you try this workaround?
  • Using Gradle toolchain support

Thoughts?

At first I tried only deleting the .gradle folders in the project, but now I tried from the user home folder. Still no success, unfortunatelly.

I tried also to add:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

But also no success.

It feels like vaadinBuildFrontend is starting a parallel task with a different Java version. But I might be wrong.

It feels like one of those problems where you miss a small configuration.

I wonder if I can find the running version and location of the Java process which is failing there.

I will try to create a sample project with the problem to post it here.

1 Like

I have prepared a sample project with the modular structure .

if you run bootRun it works fine. But if you run the production build command, then it fails.

I cannot upload to the forum so I uploaded it here:

Hi Thiago,

I can share the following repository that is a working setup of a multi-module gradle project, working with both java 17 and 21 when I build for production or run via command-line or IntelliJ:

Hope it helps. Don’t hesitate to share if it doesn’t work for you.

1 Like

Thanks! I will have a look and compare what are the differences to see what I am missing.

1 Like

Hi,

I have tested it by upgrading Hilla to the beta version and it works to compile it. But when I run the jar it tries to compile the frontend again. I am guessing it is because it is still in Beta. I will wait until the version 24.4 is released to try again. Thanks for the feedback and fix in the next version.

Just a question: To make sure something in your environment isn’t causing the issue, could you run/build the application from my repo on your local?

I did, and I got the same problem.

Steps were:

./gradlew -Philla.productionMode=true clean build

java -jar webapp/build/libs/webapp.jar

./gradlew -Philla.productionMode=true clean build

Due to integration of Hilla in Vaadin platform, the productionMode should be set in vaadin extention object instead:

./gradlew -Pvaadin.productionMode=true clean build

That makes sense.

I tried to compile it here with the correct parameter/flag and it fails on the same way.

It works on your example repository, it fails on the example I sent.

Would it make sense to exclude the failing class from the code generator?

1 Like

Actually, I couldn’t access your project uploaded on that cloud service earlier. Is it possible to share it somewhere e.g. Github?

Sorry for the delay on this. I have published the code here: