From 567ad7e885c31b5e408dd42972efd1c8309c2f82 Mon Sep 17 00:00:00 2001 From: Luciano Vernaschi Date: Thu, 2 Jan 2025 14:47:15 +0100 Subject: [PATCH] fix(gradle): restore task replacement (#3110) * Use same approach as in Maven * Re-enable task override * Restore task dependency --- .../hilla/engine/AotBrowserCallableFinder.java | 12 +++++++++--- .../vaadin/hilla/gradle/plugin/EngineGenerateTask.kt | 2 +- .../com/vaadin/hilla/gradle/plugin/HillaPlugin.kt | 2 ++ .../plugin/test/ProductionBuildFunctionalIT.java | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/AotBrowserCallableFinder.java b/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/AotBrowserCallableFinder.java index 016dfd628e..0e14c48478 100644 --- a/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/AotBrowserCallableFinder.java +++ b/packages/java/engine-core/src/main/java/com/vaadin/hilla/engine/AotBrowserCallableFinder.java @@ -89,9 +89,15 @@ private static Path generateAotArtifacts( // Runs the SpringApplicationAotProcessor to generate the // reflect-config.json file. This comes from the `process-aot` goal. - new ProcessBuilder().inheritIO().command(javaExecutable, "@" + argsFile) - .start().waitFor(); - Files.delete(argsFile); + int exitCode = new ProcessBuilder().inheritIO() + .command(javaExecutable, "@" + argsFile).start().waitFor(); + + if (exitCode == 0) { + Files.delete(argsFile); + } else { + LOGGER.error( + SPRING_AOT_PROCESSOR + " exited with code: " + exitCode); + } var json = aotOutput.resolve(Path.of("resources", "META-INF", "native-image", engineConfiguration.getGroupId(), diff --git a/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/EngineGenerateTask.kt b/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/EngineGenerateTask.kt index 49a18d39b0..4d75b85b68 100644 --- a/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/EngineGenerateTask.kt +++ b/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/EngineGenerateTask.kt @@ -34,7 +34,7 @@ public open class EngineGenerateTask : DefaultTask() { description = "Hilla Generate Task" // we need the compiled classes: - dependsOn("classes", "hillaConfigure") + dependsOn("classes") // Make sure to run this task before the `war`/`jar` tasks, so that // generated endpoints and models will end up packaged in the war/jar archive. diff --git a/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/HillaPlugin.kt b/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/HillaPlugin.kt index f0c0e82b3d..783a301885 100644 --- a/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/HillaPlugin.kt +++ b/packages/java/gradle-plugin/src/main/kotlin/com/vaadin/hilla/gradle/plugin/HillaPlugin.kt @@ -42,6 +42,8 @@ public class HillaPlugin : Plugin { // to leverage from vaadinPrepareFrontend and vaadinBuildFrontend: project.pluginManager.apply(VaadinPlugin::class.java) + project.tasks.replace("vaadinBuildFrontend", EngineBuildFrontendTask::class.java) + project.tasks.apply { register("hillaConfigure", EngineConfigureTask::class.java) register("hillaGenerate", EngineGenerateTask::class.java) diff --git a/packages/java/tests/gradle/single-module-tests/src/test/java/com/vaadin/hilla/gradle/plugin/test/ProductionBuildFunctionalIT.java b/packages/java/tests/gradle/single-module-tests/src/test/java/com/vaadin/hilla/gradle/plugin/test/ProductionBuildFunctionalIT.java index d0260c14c0..4acc61eafc 100644 --- a/packages/java/tests/gradle/single-module-tests/src/test/java/com/vaadin/hilla/gradle/plugin/test/ProductionBuildFunctionalIT.java +++ b/packages/java/tests/gradle/single-module-tests/src/test/java/com/vaadin/hilla/gradle/plugin/test/ProductionBuildFunctionalIT.java @@ -68,7 +68,7 @@ public void runProductionBuild() { } catch (IOException e) { fail(e); } - runGradleCommand("--info -Pvaadin.productionMode=true build"); + runGradleCommand("--info --stacktrace -Pvaadin.productionMode=true build"); } private void runGradleCommand(String executable) {