Hey all, can someone please help me with this topic. I am currently new to docker and just wrote my first docker file. However, when i build the the image i get this error below once the build reaches RUN ./mvnw clean install.
Error: 10.44 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.3:test (default-test) on project demo:
I do not have any current tests besides the default test that spring initializer gives you. Could it be that is the reason? Furthermore, when I run ./mvnw clean install in my terminal the my project is built with no errors. This tells me that the issue is within the docker environment. Lastly, I fixed the issue using -DskipTests within the docker file; however, I do not feel like this is a good enough solution. What if I wanted to run tests in the future?
Below is my docker file:
FROM eclipse-temurin:17-jdk-jammy as builder
WORKDIR /app
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN ./mvnw dependency:go-offline
COPY src ./src
RUN ./mvnw clean install
FROM eclipse-temurin:17-jre-jammy as final
COPY --from=builder /app/target/*.jar /app/*.jar
ENTRYPOINT ["java", "-jar", "/app/*.jar"]
This only allows us to see the surefire plugin failed, but not why. Without the actual error message, it is impossible to guess what might have caused the issue.
It is not a general problem, so it must be related either on your environment, or your code/configuration itself.
The error messages printed to the terminal are below:
10.82 [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 2.297 s <<< FAILURE! -- in com.example.demo.DemoApplicationTests
10.82 [ERROR] com.example.demo.DemoApplicationTests.contextLoads -- Time elapsed: 0.005 s <<< ERROR!
10.84 [INFO]
10.84 [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
10.84 [INFO]
10.84 [INFO] ------------------------------------------------------------------------
10.84 [INFO] BUILD FAILURE
10.84 [INFO] ------------------------------------------------------------------------
10.84 [INFO] Total time: 9.884 s
10.84 [INFO] Finished at: 2025-07-08T02:32:32Z
10.84 [INFO] ------------------------------------------------------------------------
10.84 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.3:test (default-test) on project demo:
10.84 [ERROR]
10.84 [ERROR] See /app/target/surefire-reports for the individual test results.
10.84 [ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
10.84 [ERROR] -> [Help 1]
10.84 org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.3:test (default-test) on project demo:
10.84
10.84 See /app/target/surefire-reports for the individual test results.
10.84 [ERROR]
10.84 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
10.84 [ERROR]
10.84 [ERROR] For more information about the errors and possible solutions, please read the following articles:
10.84 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
------
Dockerfile:18
--------------------
16 | RUN ./mvnw dependency:go-offline
17 | COPY src ./src
18 | >>> RUN ./mvnw clean install -e
--------------------
failed to solve: process "/bin/sh -c ./mvnw clean install -e" did not complete successfully: exit code: 1
As stated above, I currently have no tests beside the default one that spring initializer provides.
@meyay fixed your first post to use code blocks. I fixed your last one. Please, check the edit history (pencil icon in the top right corner) or read our formatting guide for more details
I have little knowledge about Java and Maven, but it seems to be a Maven issue, so I can’t help here much.
I can give an advice: Just run a container from the base image and run the commands manually in an interactive container. Than you can use your java and Maven debugging skills to figure out what happened. You can find the logs or run maven in debug mode.
If you find anything that requires Docker skills to fix the issue, we are here to help.