简体   繁体   English

我们可以将settings.xml配置到我们在Maven中的位置吗

[英]Can we configure settings.xml to our own location in maven

Recently I am working with Apache Maven in Windows machine. 最近,我正在Windows计算机中使用Apache Maven。 I am executing maven from Command Prompt every time. 我每次都从命令提示符执行maven。

I know that MAVEN will pick its settings.xml from C:\\Users\\abc\\.m2\\settings.xml 我知道,Maven将挑选其settings.xmlC:\\Users\\abc\\.m2\\settings.xml

Question : Can't I change this settings.xml to be picked from my own provided location instead of default location, like C:\\Users\\abc\\.m2\\settings.xml 问题 :我不能更改此settings.xml以从自己提供的位置而不是默认位置进行选择,例如C:\\Users\\abc\\.m2\\settings.xml

That is, instead of C:\\Users\\abc\\.m2\\settings.xml location I will configuring it in F:\\myFolder\\settings.xml . 也就是说,我将在F:\\myFolder\\settings.xml配置它,而不是C:\\Users\\abc\\.m2\\settings.xml位置。

If so, what are the steps I need to follow and check? 如果是这样,我需要遵循并检查哪些步骤?

You can change the location of user settings using the -s option from the command line: 您可以从命令行使用-s选项更改用户设置的位置:

-s,--settings <arg> Alternate path for the user settings file -s,--settings <arg>用户设置文件的备用路径

You could hence invoke Maven as following: 因此,您可以按以下方式调用Maven:

mvn clean install -s F:\myFolder\settings.xml

If you don't want to specify it at each and every invocation, since Maven 3.3.1 you can specify a .m/config folder in your project folder and a maven.config file in it providing this option. 如果不想在每次调用时都指定它,从Maven 3.3.1开始,您可以在项目文件夹中指定一个.m/config文件夹,并在其中提供一个maven.config文件来提供此选项。

The .m/config/maven.config file would have in your case the following content: 在您的情况下, .m/config/maven.config文件将包含以下内容:

-s F:\myFolder\settings.xml

And it will be applied to all Maven invocation for that project. 它将应用于该项目的所有Maven调用。

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

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