-
Notifications
You must be signed in to change notification settings - Fork 203
fix: restore cached Gradle frontend build outputs #24314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ import org.gradle.api.Plugin | |
| import org.gradle.api.Project | ||
| import org.gradle.api.plugins.JavaPlugin | ||
| import org.gradle.api.tasks.bundling.Jar | ||
| import org.gradle.api.tasks.bundling.War | ||
| import org.gradle.util.GradleVersion | ||
|
|
||
| /** | ||
|
|
@@ -72,15 +73,37 @@ public class FlowPlugin : Plugin<Project> { | |
| // In production mode, vaadinBuildFrontend is self-contained | ||
| // and performs its own frontend preparation, so there is no | ||
| // need for vaadinPrepareFrontend to run beforehand. | ||
| // this will also catch the War task since it extends from Jar | ||
| val buildFrontendTask = project.tasks.getByName("vaadinBuildFrontend") | ||
| val buildAdapter = GradlePluginAdapter(buildFrontendTask, config, false) | ||
| val vaadinServletResourcesDirectory = | ||
| buildAdapter.servletResourceOutputDirectory() | ||
| val vaadinBuildFrontendOutputDirectory = | ||
| vaadinServletResourcesDirectory.parentFile?.parentFile | ||
|
mcollovati marked this conversation as resolved.
|
||
|
|
||
| val sourceSetResourcesDirectory = | ||
| project.getBuildResourcesDir(config.sourceSetName.get()) | ||
|
|
||
| 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() | ||
| if (task.isVaadinApplicationArchiveTask()) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this condition needed? Is this to avoid the configuration for sources and Javadoc JARs?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not applying the following instruction to all JAR tasks is fundamental to make the plugin work in a backward-compatible way, but the current filter is too restrictive and might break some existing builds. Some options:
|
||
| task.dependsOn("vaadinBuildFrontend") | ||
| if (vaadinBuildFrontendOutputDirectory != null && | ||
| vaadinBuildFrontendOutputDirectory.canonicalFile != | ||
| sourceSetResourcesDirectory.canonicalFile | ||
| ) { | ||
| task.from(vaadinBuildFrontendOutputDirectory) { | ||
| task.vaadinBuildFrontendResourcesArchivePath() | ||
| ?.let { path -> | ||
| it.into(path) | ||
| } | ||
| } | ||
| } | ||
| // Restore the production token before packaging in | ||
| // case it was deleted by a previous build's cleanup. | ||
| task.doFirst { | ||
| val svc = (buildFrontendTask | ||
| as VaadinBuildFrontendTask).getTokenService().orNull | ||
| svc?.ensureToken() | ||
| } | ||
| } | ||
| } | ||
| } else if (config.alwaysExecutePrepareFrontend.get()) { | ||
|
|
@@ -149,7 +172,9 @@ public class FlowPlugin : Plugin<Project> { | |
| // all Jar/War packaging tasks have completed. | ||
| buildFrontendTask.usesService(tokenService) | ||
| project.tasks.withType(Jar::class.java) { task: Jar -> | ||
| task.usesService(tokenService) | ||
| if (task.isVaadinApplicationArchiveTask()) { | ||
| task.usesService(tokenService) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -166,4 +191,21 @@ public class FlowPlugin : Plugin<Project> { | |
| ) | ||
| } | ||
| } | ||
|
|
||
| private fun Jar.vaadinBuildFrontendResourcesArchivePath(): String? { | ||
| return when { | ||
| this is War -> "WEB-INF/classes" | ||
| isSpringBootJar() -> "BOOT-INF/classes" | ||
| else -> null | ||
| } | ||
| } | ||
|
|
||
| private fun Jar.isVaadinApplicationArchiveTask(): Boolean = | ||
| name == JavaPlugin.JAR_TASK_NAME || this is War || isSpringBootJar() | ||
|
|
||
| private fun Jar.isSpringBootJar(): Boolean = | ||
| generateSequence(javaClass as Class<*>) { it.superclass } | ||
| .any { | ||
| it.name == "org.springframework.boot.gradle.tasks.bundling.BootJar" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add a test for a plain JAR, since the plugin code allows it.