Error on build a spring boot application

I’ ve followed the tutorial on
containerize java application

And try to adat it to my need for a spring boot application I have, but when I run the build the command:

RUN --mount=type=bind,source=pom.xml,target=pom.xml \
    --mount=type=cache,target=/root/.m2 \
    ./mvnw package -DskipTests && \
    mv target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar target/app.jar

it complains saying that:

6.112 [INFO] ------------------------------------------------------------------------
6.112 [INFO] BUILD SUCCESS
6.112 [INFO] ------------------------------------------------------------------------
6.113 [INFO] Total time:  4.953 s
6.113 [INFO] Finished at: 2024-10-24T10:37:08Z
6.114 [INFO] ------------------------------------------------------------------------
8.715 mv: cannot stat 'target/ASSESSMENT_ONLINE_REST_SERVICE-1.5.2-SNAPSHOT.jar': No such file or directory

The build is done correctely and I know that the artifact ‘target/ASSESSMENT_ONLINE_REST_SERVICE-1.5.2-SNAPSHOT.jar’ has been stored in the target folder (I see if i run mvn clean install), now I’m asking:

why the command build do not see it? and this mv is for what?

You wouldn’t see the error message if the file was where you expect it to be. If you want to be sure you refer to files correctly, use absolute path in the Dockerfile so you don’t rely on the WORDKDIR setting.

You could alos use the subshell to define a variable and check the filepath it generates and also the parent folder

RUN --mount=type=bind,source=pom.xml,target=pom.xml \
    --mount=type=cache,target=/root/.m2 \
    ./mvnw package -DskipTests && \
    source="target/$(./mvnw help:evaluate -Dexpression=project.artifactId -q -DforceStdout)-$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout).jar" && \
    ls -la target/ && \
    stat "$source" && \
    mv "$source" target/app.jar

Please, don’t expect it to be 100% valid as I haven’t tried it, just sharing an idea.

By the way do you really use Docker Desktop as the category suggests? how did you install Docker?

PS.: I edited your post. Please, use code blocks as described in our formatting guide instead of quotes when sharing code, terminal output, log or anything with special characters. How to format your forum posts

1 Like