From a5a4ff192349cffea83c12ee9920254d1f546868 Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Fri, 4 Dec 2026 17:18:10 +0000 Subject: [PATCH] fix(devloop): start forked servers on the chosen JDK when JDK_HOME is set (#27683) (CP: 25.4) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Behavior deviation** · flow-devloop-daemon · developers and CI agents that run Payara Server with `JDK_HOME` set to another JDK When `JDK_HOME` points to a different JDK than the one the dev loop chose, `vaadin-dev start` on Payara Server starts the server on that other JDK. On the nightly CI agent that is Java 8, which stops at the first `--add-opens` flag, so the server never starts and every start times out. Setting `PAYARA_JAVA_HOME` is the workaround. **Risks:** - ⚠️ Behavior change: every Maven-launched application now gets `JDK_HOME` set to the chosen JDK, like `JAVA_HOME` already is. A plugin that read an inherited `JDK_HOME` on purpose now gets the dev loop's JDK. - ✅ No public API, security, memory, serialization, threading, performance or migration impact. **Context.** The daemon already sets `JAVA_HOME` and puts the chosen JDK first on `PATH`, so that a forked server runs on it. The Payara Server Maven plugin looks at `payara.java.home`, `PAYARA_JAVA_HOME`, `JDK_HOME` and only then `JAVA_HOME`, and the TeamCity agents set `JDK_HOME` to Java 8. - Set `JDK_HOME` to the chosen JDK in the environment `MavenGoalRuntime` gives the Maven process - Checked `JDK_HOME` in `MavenGoalRuntimeTest` - Documented the variable in the forked-server section of the daemon README --- flow-devloop-daemon/README.md | 5 +++++ .../com/vaadin/flow/devloop/daemon/MavenGoalRuntime.java | 5 +++++ .../com/vaadin/flow/devloop/daemon/MavenGoalRuntimeTest.java | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/flow-devloop-daemon/README.md b/flow-devloop-daemon/README.md index af52b1fa549..3bbbdbc8ebb 100644 --- a/flow-devloop-daemon/README.md +++ b/flow-devloop-daemon/README.md @@ -275,11 +275,16 @@ process: ``` JAVA_HOME= +JDK_HOME= mvnw -B -ntp -nsu [-f /pom.xml -pl : -am] -Dmaven.test.skip=true org.wildfly.plugins:wildfly-maven-plugin::run -Dwildfly.javaOpts=" " ``` +`JDK_HOME` is there because a plugin can read it before `JAVA_HOME`: Payara +Server's does, so a `JDK_HOME` the daemon inherited would otherwise start the +server on another JDK, which may refuse the loop's flags. + Every one of them deploys the packaged WAR rather than the module's own output, so one has to exist. WildFly's goal declares `@Execute(phase = PACKAGE)` and forks the packaging itself, which is why the command above names no phase, diff --git a/flow-devloop-daemon/src/main/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntime.java b/flow-devloop-daemon/src/main/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntime.java index 6256ce3ccc4..fa3d229e1b7 100644 --- a/flow-devloop-daemon/src/main/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntime.java +++ b/flow-devloop-daemon/src/main/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntime.java @@ -178,6 +178,11 @@ public Invocation invocation(Launch.Project project, List jvmFlags, // JetBrains Runtime that Jvm chose is the one the application runs on - // and with it, enhanced class redefinition. environment.put("JAVA_HOME", launch.appJvm().home().toString()); + // The same for JDK_HOME, which a forked server's plugin can read + // before JAVA_HOME. Payara Server's does, so an inherited JDK_HOME - + // a CI agent sets one to its own Java 8 - started the server on that + // JDK, which refused the loop's --add-opens and never started. + environment.put("JDK_HOME", launch.appJvm().home().toString()); // And first on the PATH, for the forked servers: a plugin that is given // no java of its own runs the first one it finds there, whatever // JAVA_HOME says. Payara Micro's does, and on Linux that was a JDK diff --git a/flow-devloop-daemon/src/test/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntimeTest.java b/flow-devloop-daemon/src/test/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntimeTest.java index 923e8c9d36c..465dd77d94e 100644 --- a/flow-devloop-daemon/src/test/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntimeTest.java +++ b/flow-devloop-daemon/src/test/java/com/vaadin/flow/devloop/daemon/MavenGoalRuntimeTest.java @@ -445,6 +445,10 @@ void invocation_forkedServerInAReactor_packsTheFlagsIntoItsParameter() .startsWith(launch.appJvm().home().resolve("bin") + File.pathSeparator), invocation.environment().get("PATH")); + // Payara Server's plugin reads JDK_HOME before JAVA_HOME, so an + // inherited one must not pick another JDK. + assertEquals(launch.appJvm().home().toString(), + invocation.environment().get("JDK_HOME")); assertFalse(Files.exists(launch.reactor().app().classesDir() .resolve("hotswap-agent.properties"))); }