英文:
Maven build: set settings.xml path from environment variable
问题
如何在mvn构建中通过环境变量设置settings.xml的路径?
我尝试过:
export MAVEN_OPTS="-s /tmp/settings.xml";
或者
export MAVEN_OPTS="--settings /tmp/settings.xml";
但是都不起作用。
我需要这样做,因为我无法修改构建命令。
英文:
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.
答案1
得分: 2
你可以在你的gitlab-ci构建脚本中尝试像这样做,就在调用mvn
之前:
(详见https://maven.apache.org/configure.html#mvn-maven-config-file)
mkdir -p .mvn && echo "-s /tmp/settings.xml" >> .mvn/maven.config
这不会修改仓库,只会在运行构建作业的本地检出中添加一个文件。
从Maven 4开始,这也应该可以工作:
export MAVEN_ARGS="-s /tmp/settings.xml"
详见https://maven.apache.org/configure.html#maven_args-environment-variable
英文:
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.
Starting with Maven 4 this should also work:
export MAVEN_ARGS="-s /tmp/settings.xml"
see https://maven.apache.org/configure.html#maven_args-environment-variable
专注分享java语言的经验与见解,让所有开发者获益!
评论