From c4b021f3b904f565943afe371efc3f1d8cfeec0d Mon Sep 17 00:00:00 2001 From: James Cox Date: Fri, 20 Mar 2026 15:10:46 -0500 Subject: [PATCH] fix(build): package frontend assets through Gradle resources - Backend packaging: - make `processResources` include the built frontend dist as an explicit `static/` resource input instead of relying on a manual copy into Gradle's output directory - keep `bootJar` as the source of truth for bundling `static/index.html` into the application jar - Docker build: - pass the frontend dist location into Gradle with `-PfrontendDistDir=/tmp/frontend-dist` - remove the ad hoc copy into `build/resources/main/static` before `bootJar` - Validation: - verify `processResources` emits `build/resources/main/static/index.html` when given a frontend dist directory - keep `git diff --check` clean for the touched packaging files --- Dockerfile | 5 +---- booklore-api/build.gradle | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index cd6df0fd0..8448e3a94 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,11 +24,8 @@ RUN --mount=type=cache,target=/home/gradle/.gradle \ COPY booklore-api/ ./ COPY --from=frontend-build /workspace/booklore-ui/dist/booklore/browser /tmp/frontend-dist -RUN mkdir -p build/resources/main/static && \ - cp -r /tmp/frontend-dist/. build/resources/main/static/ - RUN --mount=type=cache,target=/home/gradle/.gradle \ - ./gradlew --no-daemon bootJar + ./gradlew --no-daemon -PfrontendDistDir=/tmp/frontend-dist bootJar RUN set -eux; \ jar_path="$(find build/libs -maxdepth 1 -name '*.jar' ! -name '*plain.jar' | head -n 1)"; \ diff --git a/booklore-api/build.gradle b/booklore-api/build.gradle index b582ffe25..80952d709 100644 --- a/booklore-api/build.gradle +++ b/booklore-api/build.gradle @@ -10,6 +10,9 @@ plugins { group = 'org.booklore' version = '0.0.1-SNAPSHOT' +def frontendDistDir = providers.gradleProperty('frontendDistDir') + .orElse("${rootDir}/../booklore-ui/dist/booklore/browser") + java { toolchain { languageVersion = JavaLanguageVersion.of(25) @@ -141,6 +144,16 @@ jacocoTestReport { } } +tasks.named('processResources') { + def frontendResourcesDir = providers.provider { file(frontendDistDir.get()) } + inputs.dir(frontendResourcesDir) + .withPropertyName('frontendDistDir') + .optional() + from(frontendResourcesDir) { + into 'static' + } +} + bootRun { def debug = System.getenv('REMOTE_DEBUG_ENABLED') if (debug.equals("true")) { @@ -150,4 +163,4 @@ bootRun { bootJar { mainClass = 'org.booklore.BookloreApplication' -} \ No newline at end of file +}