我可以在命令行中添加 Maven 存储库吗? [英] Can I add maven repositories in the command line?
问题描述
我知道我可以添加 maven 存储库以在 ~/.m2/settings.xml 中获取依赖项.但是是否可以使用命令行添加存储库,例如:
I'm aware I can add maven repositories for fetching dependencies in ~/.m2/settings.xml. But is it possible to add a repository using command line, something like:
mvn install -Dmaven.repository=http://example.com/maven2
我想这样做的原因是因为我使用了一个持续集成工具,我可以完全控制它用来调用 maven 的命令行选项,但为运行集成工具的用户管理 settings.xml有点麻烦.
The reason I want to do this is because I'm using a continuous integration tool where I have full control over the command line options it uses to call maven, but managing the settings.xml for the user that runs the integration tool is a bit of a hassle.
推荐答案
您可以这样做,但正如其他人所说,您最好在 POM 中这样做.
You can do this but you're probably better off doing it in the POM as others have said.
在命令行上,您可以为本地存储库指定一个属性,并为远程存储库指定另一个存储库.尽管远程存储库将具有所有默认设置
On the command line you can specify a property for the local repository, and another repository for the remote repositories. The remote repository will have all default settings though
下面的示例指定了两个远程存储库和一个自定义本地存储库.
The example below specifies two remote repositories and a custom local repository.
mvn package -Dmaven.repo.remote=http://www.ibiblio.org/maven/,http://myrepo
-Dmaven.repo.local="c: est
epo"
这篇关于我可以在命令行中添加 Maven 存储库吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!