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") 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() + } } } }