Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven build: set settings.xml path from environment variable

Tags:

java

maven

build

How can I set the path of the settings.xml from environment variable in a mvn build?

I have tried:

export MAVEN_OPTS="-s /tmp/settings.xml"

or

export MAVEN_OPTS="--settings /tmp/settings.xml"

but it not works.

I need it, because I cannot modify the build command.

like image 965
Dániel Kis Avatar asked Aug 08 '26 16:08

Dániel Kis


1 Answers

Starting with Maven 3.9, you can set it through MAVEN_ARGS:

export MAVEN_ARGS="--settings /tmp/settings.xml"

If you are using an older version, you could try something like this in your gitlab-ci build script, just before calling mvn:
(see https://maven.apache.org/configure.html#mvn-maven-config-file)

mkdir -p .mvn && echo "-s /tmp/settings.xml" >> .mvn/maven.config

This does not modify the repo, only adds a file to the local checkout within the running build job.

like image 51
flesser Avatar answered Aug 11 '26 07:08

flesser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!