Vlastimil Brecka
02/04/2025, 4:36 PMFROM bellsoft/liberica-openjdk-alpine:17 AS build-environment
WORKDIR /product-app
# Cache gradlew
COPY gradlew build.gradle settings.gradle ./ <-----------------
COPY gradle gradle <-----------------
RUN ./gradlew tasks <-----------------
# Copy sources & build
COPY . .
RUN ./gradlew :app:bootJar
is this an idiomatic way to create `Dockerfile`s when building with ./gradlew
?
is there maybe something neater? or possible a single copy command?Vampire
02/04/2025, 4:41 PMtasks
task?
Why can't you right away copy the project and run Gradle?Vlastimil Brecka
02/04/2025, 4:46 PMJulien Plissonneau Duquène
02/04/2025, 5:41 PM--volume
or an included script that downloads the sources from your VCS server and then starts the build). Building the project at container build time is wasteful unless you use these container images to actually run the project.Vlastimil Brecka
02/04/2025, 5:46 PMVampire
02/04/2025, 5:49 PMotherwise if you only change app sourxes you end up downloading gradle binary everytimeQuite some time since I built a Docker image, but what you showed does not build an intermediate stage, does it? Wouldn't you need an intermediate
FROM
to enter a new build stage?Vlastimil Brecka
02/04/2025, 5:53 PMVlastimil Brecka
02/04/2025, 5:53 PMVampire
02/04/2025, 6:08 PMJulien Plissonneau Duquène
02/04/2025, 6:09 PMhow do you prepopulate the gradle cache without triggering a gradle build?That's a good question. Maven has a convenient
dependency:go-offline
feature, but I could not find an equivalent feature in Gradle.
However you can use the dependency verification feature (in bootstrap mode) to work around that, as it will download the dependencies to compute their checksums. It would probably be a good idea to then overwrite (or move) the generated file and rerun the verification with a trusted file, to make your supply chain a bit more secure.
https://docs.gradle.org/current/userguide/dependency_caching.html#sec:cache-copyJulien Plissonneau Duquène
02/04/2025, 6:14 PM