Closed ckyeon closed 1 year ago
Problem
While following the guide, I found that the gradle Dockerfile example of Multi-Stage Build did not working.
# syntax=docker/dockerfile:experimental FROM eclipse-temurin:17-jdk-alpine AS build WORKDIR /workspace/app COPY . /workspace/app RUN --mount=type=cache,target=/root/.gradle ./gradlew clean build RUN mkdir -p build/dependency && (cd build/dependency; jar -xf ../libs/*.jar) FROM eclipse-temurin:17-jdk-alpine VOLUME /tmp ARG DEPENDENCY=/workspace/app/build/dependency COPY --from=build ${DEPENDENCY}/BOOT-INF/lib /app/lib COPY --from=build ${DEPENDENCY}/META-INF /app/META-INF COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app ENTRYPOINT ["java","-cp","app:app/lib/*","hello.Application"]
The unpack command(
jar -xf ../libs/*.jar
) in the example above doens't work.The other examples worked fine, so I looked for differences.
work
jar -xf ../*.jar
not work
jar -xf ../libs/*.jar
For some reason, the
*
pattern doesn't seem to work when the path contains directories. (It was the same on macOS terminal.)Solve
find ../libs -name "*.jar" -exec jar -xf {} \;
reference: https://stackoverflow.com/questions/45975019/extract-several-of-jar-in-one-command
Because it is a translator, sentences can be awkward. Thanks for reading π
The cause of the problem seems to be that there are two *.jar files in gradle.
*-SNAPSHOT.jar
*-SNAPSHOT-plain.jar
run build/dependency
find ../libs -name "*.jar"
<result>
../libs/docker-0.0.1-SNAPSHOT-plain.jar
../libs/docker-0.0.1-SNAPSHOT.jar
run target/dependency
find .. -name "*.jar"
<result>
../docker-0.0.1-SNAPSHOT.jar
jar -xf ../libs/*-SNAPSHOT.jar
@dsyer If you are not busy, please review this PR π
LGTM. I think maybe this changed in gradle since the guide was written.
Problem
While following the guide, I found that the gradle Dockerfile example of Multi-Stage Build did not working.
The unpack command(
jar -xf ../libs/*.jar
) in the example above doens't work.The other examples worked fine, so I looked for differences.
work
not work
For some reason, the
*
pattern doesn't seem to work when the path contains directories.(It was the same on macOS terminal.)
Solve
reference: https://stackoverflow.com/questions/45975019/extract-several-of-jar-in-one-command
Because it is a translator, sentences can be awkward. Thanks for reading π