M2Eclipse:从Eclipse工作区解析Maven依赖项 [英] M2Eclipse: Resolving Maven dependencies from the Eclipse workspace

查看:163
本文介绍了M2Eclipse:从Eclipse工作区解析Maven依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

M2Eclipse主页指出该插件具有以下功能:

The M2Eclipse Homepage states that the plugin is capable of the following:

不使用Eclipse工作区即可解决Maven依赖关系 安装到本地Maven存储库

Resolving Maven dependencies from the Eclipse workspace without installing to local Maven repository

由于我没有找到任何文档,所以我无法弄清楚这到底意味着什么以及它是如何完成的.在工作空间中的项目对应于两个不同的jar(它们都包含类的一部分)的情况下,我尤其感兴趣.

As I did not find any documentation, I could not figure out what this exactly means and how it is done. I am especially interested in cases where a project in workspace corresponds to two different jars (which both contain parts of the classes).

推荐答案

Eclipse工作区(使用M2E时)充当本地maven存储库.您签出的每个Maven项目都可以用作依赖项(就像您已将其安装在本地存储库中一样).

The Eclipse workspace (when using M2E) acts as a local maven repository. Every Maven project you have checked out is available to be used as a dependency (just as if you had installed it on your local repository).

例如:如果您的项目A依赖于1.0.0版本的lib B,并且您签出了1.0.0版的lib B的源代码,那么Eclipse将能够使用B的工作空间版本来编译A.您不会需要在本地存储库上安装libB.

For example: If your project A depends on lib B version 1.0.0 and you check out the source for lib B on version 1.0.0, Eclipse will be able to compile A using the workspace version of B. You will not need to install lib B on your local repository.

当您需要对lib进行更改并在工作区中也有的应用程序中对其进行测试时,这特别有用.

This is specially useful when you need to make changes to a lib and test it in an application you also have on your workspace.

不过,请注意,pom A上lib B的依赖版本和pom B上B的声明版本必须完全匹配才能起作用.例如,如果在pom.xml上有A,您将拥有:

Notice, though, that the version of the dependency for lib B on the pom A and the declared version of B on pom B must match EXACTLY for this to work. For example, if on pom.xml for A you have:

 <dependency>
        <groupId>a.b.c</groupId>
        <artifactId>B</artifactId>
        <version>1.0.0</version>
 </dependency>

您需要在1.0.0版上使用结帐B.

You need the checkout B on version 1.0.0.

如果需要在B上进行更改,则可能必须将依赖项版本更改为-SNAPSHOT(例如1.0.1-SNAPSHOT),并检查B的那个版本.

If you need to make changes on B, you will probably have to change your dependency version to something-SNAPSHOT (1.0.1-SNAPSHOT, for example) and check out that version of B.

您还需要检查Eclipse项目上的解决工作空间工件"选项,以使其起作用. (右键单击项目->属性-> Maven->解决工作区项目中的依赖项)

You also need to check the option "Resolve workspace artifacts" on your Eclipse project for this to work. (Right click the project -> Properties -> Maven -> Resolve dependencies from Workspace Projects)

如果要确保Eclipse使用的是工作空间上的版本,而不是已安装的版本(甚至是远程存储库中的版本),请检查pom.xml编辑器上的依赖关系"选项卡. 常规"依赖项用jar图标显示,在工作区(如lib B)上解析的依赖项用Eclipse项目图标显示.

If you want to make sure that Eclipse is using the version on your workspace and not an installed version (or even a version from a remote repository), check the "Dependencies" tab on the pom.xml Editor. The "regular" dependencies are shown with jar icons, the dependencies resolved on the workspace (like lib B) are shown with Eclipse project icons.

这篇关于M2Eclipse:从Eclipse工作区解析Maven依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆