docker-maven
docker-maven copied to clipboard
Trouble with ${revision} in Docker builds
pom.xml has <version>${revision}</version>
with a corresponding <revision>0.0.9</revision>
in the <properties>
section. Running mvn clean package
from terminal and from within IntelliJ work fine. However same code building from Docker fails.
When I replace ${revision}
and ${changelist}
with explicit versions instead of property references, it builds fine.
Relevant Dockerfile snippet leading up to RUN error.
FROM maven:3-eclipse-temurin-21-alpine AS build
WORKDIR /build
COPY . .
RUN mvn clean package --batch-mode -DskipTests
returns
=> ERROR [build 4/6] RUN mvn clean package --batch-mode -DskipTests
------
> [build 4/6] RUN mvn clean package --batch-mode -DskipTests:
0.746 [INFO] Scanning for projects...
0.875 [INFO] Downloading from cloudy-clouds-deps: https://artifactory.acorn.cirrostratus.org/artifactory/maven/org/cirrostratus/sequoia/ims-parent/$%7Brevision%7D/ims-parent-$%7Brevision%7D.pom
2.079 [ERROR] [ERROR] Some problems were encountered while processing the POMs:
2.079 [FATAL] Non-resolvable parent POM for org.cirrostratus.sequoia:ims-mailer-service:${changelist}: The following artifacts could not be resolved: org.cirrostratus.sequoia:ims-parent:pom:${revision} (absent): Could not find artifact org.cirrostratus.sequoia:ims-parent:pom:${revision} in cloudy-clouds-deps (https://artifactory.acorn.cirrostratus.org/artifactory/maven) and 'parent.relativePath' points at wrong local POM @ line 5, column 13
2.079 @
2.080 [ERROR] The build could not read 1 project -> [Help 1]
2.080 [ERROR]
2.080 [ERROR] The project org.cirrostratus.sequoia:ims-mailer-service:${changelist} (/build/pom.xml) has 1 error
2.081 [ERROR] Non-resolvable parent POM for org.cirrostratus.sequoia:ims-mailer-service:${changelist}: The following artifacts could not be resolved: org.cirrostratus.sequoia:ims-parent:pom:${revision} (absent): Could not find artifact org.cirrostratus.sequoia:ims-parent:pom:${revision} in cloudy-clouds-deps (https://artifactory.acorn.cirrostratus.org/artifactory/maven) and 'parent.relativePath' points at wrong local POM @ line 5, column 13 -> [Help 2]
2.081 [ERROR]
2.082 [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
2.082 [ERROR] Re-run Maven using the -X switch to enable full debug logging.
2.082 [ERROR]
2.082 [ERROR] For more information about the errors and possible solutions, please read the following articles:
2.082 [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
2.082 [ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
------
Dockerfile:20
--------------------
18 |
19 | # Skip tests since we are testing in another job. This will speed up the pipeline.
20 | >>> RUN mvn clean package --batch-mode -DskipTests
21 |
22 | # Copy the fat jar to the root of the build directory
--------------------
ERROR: failed to solve: process "/bin/sh -c mvn clean package --batch-mode -DskipTests" did not complete successfully: exit code: 1
Fixed by adding the following after COPYing the pom.xml file into the container image:
RUN sed -i "s/\${revision}/$(awk -F'[<>]' '/<revision>/{print $3}' pom.xml)/g" pom.xml
Reads the revision parameter and then replaces the ${revision}
placeholder in the pom file. Uses sed and awk, so should be available in any Linux container.