Skip to content

Commit 63e4d4d

Browse files
authored
fix: Propagate build info in vaadinBuildFrontend when token file is missing (#22800)
Add defensive build info propagation to the vaadinBuildFrontend task, mirroring the fix from PR #22726 for the Maven plugin. Instead of failing with a hard check when the token file doesn't exist, the task now automatically propagates build info to create it. This makes the Gradle plugin more resilient in edge cases where the token file might be missing, such as after incremental builds or when task dependencies are bypassed. Related to #22679
1 parent 229fdfa commit 63e4d4d

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,4 +750,62 @@ class MiscSingleModuleTest : AbstractGradleTest() {
750750
expect(true, buildResult.output) { buildResult.output.contains("!!!effective1.productionMode=true!!!") }
751751
expect(true, buildResult.output) { buildResult.output.contains("!!!effective2.productionMode=true!!!") }
752752
}
753+
754+
/**
755+
* Tests https://github.com/vaadin/flow/issues/22679
756+
* Verifies that vaadinBuildFrontend can propagate build info
757+
* if the token file doesn't exist, making it possible to run
758+
* without vaadinPrepareFrontend in edge cases.
759+
*/
760+
@Test
761+
fun testBuildFrontendPropagatesBuildInfo() {
762+
testProject.buildFile.writeText(
763+
"""
764+
plugins {
765+
id 'war'
766+
id 'org.gretty' version '4.0.3'
767+
id("com.vaadin.flow")
768+
}
769+
repositories {
770+
mavenLocal()
771+
mavenCentral()
772+
maven { url = 'https://maven.vaadin.com/vaadin-prereleases' }
773+
}
774+
dependencies {
775+
implementation("com.vaadin:flow:$flowVersion")
776+
providedCompile("jakarta.servlet:jakarta.servlet-api:6.0.0")
777+
implementation("org.slf4j:slf4j-simple:$slf4jVersion")
778+
}
779+
""".trimIndent()
780+
)
781+
782+
// First, run prepare and build to ensure everything works normally
783+
val build1: BuildResult = testProject.build("-Pvaadin.productionMode", "build")
784+
build1.expectTaskSucceded("vaadinPrepareFrontend")
785+
build1.expectTaskSucceded("vaadinBuildFrontend")
786+
787+
// Verify token file was created
788+
val tokenFile = File(testProject.dir, "build/resources/main/META-INF/VAADIN/config/flow-build-info.json")
789+
expect(true) { tokenFile.exists() }
790+
val tokenFileContent = JacksonUtils.readTree(tokenFile.readText())
791+
expect("app-" + StringUtil.getHash(testProject.dir.name,
792+
java.nio.charset.StandardCharsets.UTF_8
793+
)) { tokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
794+
795+
// Clean the token file to simulate it not existing
796+
tokenFile.delete()
797+
expect(false) { tokenFile.exists() }
798+
799+
// Run vaadinBuildFrontend again - it should propagate build info
800+
// even though the token file doesn't exist
801+
val build2: BuildResult = testProject.build("-Pvaadin.productionMode", "vaadinBuildFrontend")
802+
build2.expectTaskSucceded("vaadinBuildFrontend")
803+
804+
// Verify token file was re-created by propagation
805+
expect(true) { tokenFile.exists() }
806+
val newTokenFileContent = JacksonUtils.readTree(tokenFile.readText())
807+
expect("app-" + StringUtil.getHash(testProject.dir.name,
808+
java.nio.charset.StandardCharsets.UTF_8
809+
)) { newTokenFileContent.get(InitParameters.APPLICATION_IDENTIFIER).textValue() }
810+
}
753811
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ public abstract class VaadinBuildFrontendTask : DefaultTask() {
8181
public fun vaadinBuildFrontend() {
8282
val config = adapter.get().config
8383
logger.info("Running the vaadinBuildFrontend task with effective configuration $config")
84-
// sanity check
8584
val tokenFile = BuildFrontendUtil.getTokenFile(adapter.get())
86-
check(tokenFile.exists()) { "token file $tokenFile doesn't exist!" }
85+
if (!tokenFile.exists()) {
86+
// if prepare-frontend token file doesn't exist, propagate build info
87+
// to token file
88+
logger.info("Token file does not exist, propagating build info")
89+
BuildFrontendUtil.propagateBuildInfo(adapter.get())
90+
}
8791

8892
val options = Options(null, adapter.get().classFinder, config.npmFolder.get())
8993
.withFrontendDirectory(BuildFrontendUtil.getFrontendDirectory(adapter.get()))

0 commit comments

Comments
 (0)