No way to pass MAVEN_OPTS to Dockerfile(safely)

Hey there, I am trying to pass environment variable MAVEN_OPTS to the Dockerfile so mvn clean package use those args(such as -DskipTests -Djasypt.plugin.path=“file:src/main/resources/application.yml”…) with no success. As I see environment variables of are only available while packaging (mvn package) and not in execution of Dockerfile. Since there is no way to change docker build behaviour I think I will get rid of all MAVEN_OPTS args and create one environment variable since it is the unique workaround I see.
However I suggest you to implement this feature since it should be simple to archieve and enhances security(I just have few keys but I would be upset if I had to get rid of encryption of java properties file and build 100 environment variables instead).

Just make an input in the UI to let add ARGs that might be referenced from Dockerfile, such as docker build --build-arg MAVEN_OPTS=“-DskipTests…” …

FROM maven:3.8.2-openjdk-17 AS build
COPY . .
RUN mvn clean package


The Docker snippet looks correct as outlined in Environment Variables in Docker Builds.

You’d then set MAVEN_OPTS as an Environment Variable on the services “Environment” page.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.