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

huangapple go评论80阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年4月7日 19:49:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/61079389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定