From 7de762b0bab89c4c32a8e86188b23119721b12bc Mon Sep 17 00:00:00 2001 From: Ingo Kegel Date: Wed, 24 Jun 2026 15:54:14 +0200 Subject: [PATCH 1/2] fix: support the configuration cache when packaging the production jar The production-mode token-restore action was added as a Jar.doFirst {} whose lambda captures the whole Project, which can't be serialized for the configuration cache. It's moved to the block where the vaadinBuildFrontendToken service is already in scope, and now captures that service provider instead of the Project. Fixes #24794 --- .../main/kotlin/com/vaadin/gradle/FlowPlugin.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/FlowPlugin.kt b/flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/FlowPlugin.kt index 93024da4726..6d26e2a055b 100644 --- a/flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/FlowPlugin.kt +++ b/flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/FlowPlugin.kt @@ -75,13 +75,6 @@ public class FlowPlugin : Plugin { // this will also catch the War task since it extends from Jar project.tasks.withType(Jar::class.java) { task: Jar -> task.dependsOn("vaadinBuildFrontend") - // Restore the production token before packaging in - // case it was deleted by a previous build's cleanup. - task.doFirst { - val svc = (project.tasks.getByName("vaadinBuildFrontend") - as VaadinBuildFrontendTask).getTokenService().orNull - svc?.ensureToken() - } } } else if (config.alwaysExecutePrepareFrontend.get()) { // In development mode, vaadinPrepareFrontend is not @@ -150,6 +143,13 @@ public class FlowPlugin : Plugin { buildFrontendTask.usesService(tokenService) project.tasks.withType(Jar::class.java) { task: Jar -> task.usesService(tokenService) + // Restore the production token before packaging in + // case it was deleted by a previous build's cleanup. + // Capture the service provider rather than the Project so + // the action stays compatible with the configuration cache. + task.doFirst { + tokenService.get().ensureToken() + } } } } From 34a4d7f6bf8923d3bd816d1206c2bf377125e08f Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Wed, 24 Jun 2026 17:09:22 +0200 Subject: [PATCH 2/2] test: cover config cache with production jar packaging The config-cache regression in #24794 went unnoticed because the existing configuration-cache tests only run the `vaadinBuildFrontend` task, which never puts a `Jar`/`War` task in the task graph. The faulty token-restore action lived on the packaging task, so the cache never attempted to serialize it. Add a functional test that runs the `war` task with `--configuration-cache` in production mode, exercising the packaging task's `doFirst` action. Against the pre-fix code it reproduces the `cannot serialize object of type 'DefaultProject'` failure; with the fix in place the configuration cache entry is stored and reused. Part of #24794 --- .../com/vaadin/gradle/VaadinSmokeTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/VaadinSmokeTest.kt b/flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/VaadinSmokeTest.kt index b0a5f3ab713..bf55c243346 100644 --- a/flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/VaadinSmokeTest.kt +++ b/flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/VaadinSmokeTest.kt @@ -707,6 +707,27 @@ class VaadinSmokeTest : AbstractGradleTest() { assertContains(result.output, "Calculating task graph as no cached configuration is available for tasks: vaadinBuildFrontend") } + @Test + fun testWarPackaging_configurationCache_productionMode() { + // Regression test for https://github.com/vaadin/flow/issues/24794 + // In production mode the token-restore action is attached to the + // Jar/War packaging task. If that action captures the Project, the + // configuration cache cannot serialize the War task and the build + // fails. The existing config-cache tests only run vaadinBuildFrontend, + // so they never exercise the packaging task; this test does. + + // Create frontend folder, that will otherwise be created by the first + // execution, invalidating the cache on the second run + testProject.newFolder("src/main/frontend") + + val result = testProject.build("--configuration-cache", "-Pvaadin.productionMode", "war") + result.expectTaskSucceded("war") + assertContains(result.output, "Configuration cache entry stored") + + val result2 = testProject.build("--configuration-cache", "-Pvaadin.productionMode", "war", checkTasksSuccessful = false) + assertContains(result2.output, "Reusing configuration cache") + } + private fun enableHilla() { testProject.newFolder(FrontendUtils.DEFAULT_FRONTEND_DIR) testProject.newFile(FrontendUtils.DEFAULT_FRONTEND_DIR + "index.ts")