Skip to content

Commit 48c114b

Browse files
fix: skip vaadinBuildFrontend in development mode (#25002) (CP: 25.2) (#25006)
This PR cherry-picks changes from the original PR #25002 to branch 25.2. --- #### Original PR description > The Gradle vaadinBuildFrontend task is now skipped when Vaadin production > mode is not enabled. This prevents development and multi-module builds from > failing when the task is part of the build graph, and avoids producing a > production configuration while running in development mode. > > Fixes #25000 Co-authored-by: Marco Collovati <marco@vaadin.com>
1 parent 4855ad6 commit 48c114b

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎flow-plugins/flow-gradle-plugin/src/functionalTest/kotlin/com/vaadin/gradle/VaadinSmokeTest.kt‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,26 @@ class VaadinSmokeTest : AbstractGradleTest() {
8989
expect(false, build.toString()) { build.exists() }
9090
}
9191

92+
@Test
93+
fun `vaadinBuildFrontend is skipped in development mode when explicitly required`() {
94+
// Some projects wire vaadinBuildFrontend into the build graph, e.g.
95+
// jar.dependsOn('vaadinBuildFrontend'). In development mode the task
96+
// must be skipped rather than failing the build (the production-only
97+
// token service is not registered) or writing a production token.
98+
// See https://github.com/vaadin/flow/issues/25000
99+
testProject.buildFile.appendText("""
100+
tasks.named('jar') {
101+
dependsOn('vaadinBuildFrontend')
102+
}
103+
""".trimIndent())
104+
105+
val result: BuildResult = testProject.build("jar", checkTasksSuccessful = false)
106+
result.expectTaskOutcome("vaadinBuildFrontend", TaskOutcome.SKIPPED)
107+
108+
val build = File(testProject.dir, "build/resources/main/META-INF/VAADIN/webapp/VAADIN/build")
109+
expect(false, build.toString()) { build.exists() }
110+
}
111+
92112
@Test
93113
fun testBuildFrontendInProductionMode() {
94114
val result: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend")

‎flow-plugins/flow-gradle-plugin/src/main/kotlin/com/vaadin/gradle/VaadinBuildFrontendTask.kt‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ public abstract class VaadinBuildFrontendTask : DefaultTask() {
151151
internal fun configure(config: PluginEffectiveConfiguration) {
152152
adapter.set(GradlePluginAdapter(this, config, false))
153153

154+
// vaadinBuildFrontend builds the optimized production bundle and
155+
// writes a flow-build-info.json token with productionMode=true; it
156+
// is only meaningful for production builds. Skip it in development
157+
// mode so that an explicit dependency on the task (e.g.
158+
// jar.dependsOn('vaadinBuildFrontend')) cannot overwrite the
159+
// development token and make the running application behave as in
160+
// production, and so the build does not fail because the
161+
// production-only token build service is not registered (the
162+
// service is registered by FlowPlugin only in production mode).
163+
val productionMode = config.productionMode
164+
onlyIf("Vaadin production mode is enabled") { productionMode.get() }
165+
154166
// Track user-written frontend source files, excluding the
155167
// generated/ subdirectory (modified by this task) and index.html
156168
// (may be created by this task when missing; tracked as an output

0 commit comments

Comments
 (0)