简体   繁体   English

Maven 构建:从环境变量设置 settings.xml 路径

[英]Maven build: set settings.xml path from environment variable

How can I set the path of the settings.xml from environment variable in a mvn build?如何在 mvn 构建中从环境变量设置 settings.xml 的路径?

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.我需要它,因为我无法修改构建命令。

You could try something like this in your gitlab-ci build script, just before calling mvn :你可以在你的 gitlab-ci 构建脚本中尝试这样的事情,就在调用mvn之前:
(see https://maven.apache.org/configure.html#mvn-maven-config-file ) (参见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.这不会修改 repo,只会将文件添加到正在运行的构建作业中的本地签出。


Starting with Maven 4 this should also work:从 Maven 4 开始,这也应该有效:

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

see https://maven.apache.org/configure.html#maven_args-environment-variablehttps://maven.apache.org/configure.html#maven_args-environment-variable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM