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).
Right-click the project, then Maven > Enable Workspace Resolution.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With