简体   繁体   English

如何在Eclipse中管理不同项目的不同Maven设置?

[英]How to manage different maven setting in eclipse for different projects?

I am working on two different projects, Both uses different maven .settings.xml files. 我正在两个不同的项目上,都使用不同的maven .settings.xml文件。
When I switch between the projects, it re downloads all the maven dependencies in repository folder removing previous projects' dependencies. 当我在项目之间切换时,它将重新下载存储库文件夹中的所有maven依赖项,从而删除了先前项目的依赖项。
Is there any way I can use two settings and it maintains different repository for both projects. 有什么办法可以使用两个settings并且为两个项目维护不同的存储库。

You can try to separate the two projects in different workspaces and you can configure each workspace with eclipse, it is possible because eclipse saves the configuration within each workspace, so you can specify the different repositories with their maven settings.xml files. 您可以尝试将两个项目分隔在不同的工作空间中,并且可以使用eclipse配置每个工作空间,这是可能的,因为eclipse会将配置保存在每个工作空间中,因此您可以使用其maven settings.xml文件指定不同的存储库。

For to do that, launch eclipse > go to preferences > choose maven > User Settings and click on "Update Settings" 为此,启动eclipse>转到首选项>选择maven>用户设置 ,然后单击“更新设置”。

在此处输入图片说明

UPDATE: 更新:

You should have a structure similar to the following: 您应该具有类似于以下内容的结构:

Workspaces: 工作区:

/Volumes/Stonehall/juanca/workspace-project-1/
/Volumes/Stonehall/juanca/workspace-project-2/

Repositories: 仓库:

/Volumes/Stonehall/juanca/.m2/settings-project-1.xml
/Volumes/Stonehall/juanca/.m2/settings-project-2.xml

Open and edit settings-project-1.xml file. 打开并编辑settings-project-1.xml文件。 Searchs the localRepository tag and replace the path, for example: 搜索localRepository标记并替换路径,例如:

<localRepository>/Volumes/Stonehall/juanca/.m2/repository-1/</localRepository>

Open and edit settings-project-2.xml file. 打开并编辑settings-project-2.xml文件。 Searchs the localRepository tag and replace with the other path, for example: 搜索localRepository标记并替换为其他路径,例如:

<localRepository>/Volumes/Stonehall/juanca/.m2/repository-2/</localRepository>

Important: checks that the <localRepository> tag is not commented for example: 重要提示:检查<localRepository>标记是否未注释,例如:

<!--
...
<localRepository>/Volumes/Stonehall/juanca/.m2/repository/</localRepository>
-->

Eclipse: 日食:

Open the workspace-project-1 , go to preferences > choose maven > User Settings and click on "Update Settings" and replace with the new path: 打开workspace-project-1 ,转到首选项>选择maven> User Settings ,然后单击“ Update Settings”并替换为新路径:

/Volumes/Stonehall/juanca/.m2/settings-project-1.xml

The same way you should do for the workspace-project-2 , open the workspace-project-2 and go to preferences > choose maven > User Settings and click on "Update Settings" and replace with the other path: 您应该对workspace-project-2 ,打开workspace-project-2然后转到首选项>选择maven> User Settings ,然后单击“ Update Settings”并替换为其他路径:

/Volumes/Stonehall/juanca/.m2/settings-project-2.xml

With this configuration each project should download the dependencies in the differents repositories. 使用此配置,每个项目都应在不同的存储库中下载依赖项。

This configuration should work, but in case does not work, you should post your settings.xml file and the pom files of both projects, so that we can help you better 此配置应该可以,但是如果不起作用,则应发布两个项目的settings.xml文件和pom文件,以便我们更好地帮助您

You can create 2 separate workspaces in Eclipse. 您可以在Eclipse中创建2个独立的工作区。 In each workspaces, you can provide respective settings.xml file 在每个工作空间中,您可以提供各自的settings.xml文件

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

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