Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

M2Eclipse: Resolving Maven dependencies from the Eclipse workspace

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

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

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).

like image 246
J Fabian Meier Avatar asked Jan 11 '16 15:01

J Fabian Meier


People also ask

How do I turn on Maven workspace resolution?

Right-click the project, then Maven > Enable Workspace Resolution.

How do I force Maven to download dependencies in Eclipse?

Via the Maven index, you can search for dependencies, select them and add them to your pom file. To download the index, select Windows > Preferences > Maven and enable the Download repository index updates on startup option. After changing this setting, restart Eclipse. This triggers the download of the Maven index.


1 Answers

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).

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.

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.

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>

You need the checkout B on version 1.0.0.

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.

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)

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.

like image 164
Isabella Almeida Avatar answered Sep 16 '22 19:09

Isabella Almeida