What is the difference between maven update and maven build? - eclipse

With m2e-plugin we can right click on a project and then click on Maven update or we can click on Run As -> Maven build. What is the difference between them? What is the background operation that is performed when each option is chosen?
Because as far as I can see.. the information provided in that status bar says that it is "Building the workpace". What does it mean by that?
What exactly is updating the project?

When you run maven update - your local maven repository gets updated with the latest jars from central repository. This is important for SNAPSHOT versions of artifacts. SNAPSHOT version of artifacts in the local repository maybe out of date with what's currently available in your central repository.
*build happens in eclipse because the build automatically option is selected. if it's not it won't happen.
When build - complies, runs test and builds you current projects artifacts. maven build usually includes a maven update phase unless run with the offline option (-o).

Related

M2Eclipse: Automatically execute Maven when pom.xml changes?

For an Eclipse plugin project I need a p2 local repository to be automatically deployed with dependencies defined in the pom.
The best way (or the only way that really works) to do so is to use org.reficio plugin p2-maven-plugin.
Therefore I created a general project in Eclipse to prepare and hold the repository and a pom.xml that generates this repository.
When I execute the goal p2:site the repository is created successfully.
Now I am trying to make Eclipse with M2Eclipse to automatically execute that goal whenever the file pom.xml has ben changed (e.g. the user has added a new dependency or the file has been changed because an updated file has been downloaded from the SCM repository.
Is there a way to make M2Eclipse respectively it's Maven Project Builder to execute this phase automatically?

Eclipse - Maven and Mercurial

I have a remote Mercurial repository containing Maven projects. I would like to clone it into my Eclipse workspace for development.
I currently have Maven Integration for Eclipse installed through Eclipse Marketplace. I also have MercurialEclipse. But I can't checkout the code as Maven projects. When I checkout normally, only the parent project code is fully downloaded which makes sense because the Maven nature is not identified.
I have svn integrated fine, and I have the plugin "Maven SCM Handler for Subclipse" so I can easily checkout the projects from svn as Maven projects. Is there something like this for Mercurial?
Also I checked "File->New->Other->Maven->Checkout Maven Projects from SCM", and I see only svn in the dropdown.
Please let me know if the Maven-Mercurial integration in eclipse is possible.
Thanks for looking into this.
I do that every day at work and there is a small trick for it.
Try to do it in this order:
clone the project from command line
then in eclipse import the project as a maven project
then right click on the project and select team->share->mercurial
follow the dialog boxes and eventually you will get to the one asking you the url of the scm.
And that's it.
For multiple module project, you might have to repeat steps 3 and 4 for each of them.
For info i am using the version 1.2.0 of the maven plugin and for the mercurial one i use the one from the new website: https://bitbucket.org/mercurialeclipse/main/wiki/Home
and configured with an external mercurial client.
You can clone and configure a multiple module project using MercurialEclipse and Maven plugins from Eclipse IDE performing the following steps.
Clone the project in Eclipse IDE using MercurialEclipse.
Right click on the cloned project in the Project Explorer, select "Configure" and then "Convert to Maven Project".
Select File, Import and "Existing Maven Project" and click Next. You will get your cloned project and modules automatically selected on the next screen, so just need to click Finish button.
Finally, you will get your multi module project cloned and configured as maven project.
I use MercurialEclipse plugin and do Checkout in other way:
Clone repository
File -> New -> Project...
Select Mercurial -> Clone Existing Mercurial Repository Next >
Type URL, Auth data, and Clone directory name (optional) Finish
Prepare project for Eclipse
Generate Eclipse files: execute mvn eclipse:eclipse in command line
Refresh project (via context menu or F5)
Sometimes in the end you need to select the right encoding:
Open Project properties
Set Resource -> Text file encoding to Other

Eclipse Maven - Auto Increment pom version before committing to GitHub?

I am looking for a solution to this. Here is my setup:
Local Eclipse with all maven projects on. When i commit them to GitHub, my Jenkins server automatically builds the project. (For every push to github)
However, in my Maven repository on the Jenkins server, i want to be able to get each one (1.0.1 -> 1.0.2 etc.) is there any way i can do this? Ideally an eclipse plugin so that it changes the version before it gets to GitHub.
If i used the maven-version-plugin, it would not update on my local eclipse machine, therefore it would just use the same version each time.
Any Solutions?
I would suggest to use the maven-release-plugin which exactly does things like this. This comprises of two steps. First mvn release:prepare and second mvn release:perform.

maven - inter workspace dependencies

i am using eclipse and maven integration.
maven install puts the resources to the local repositories. local repositories is divided into "local repository" and "workspace projects" as shown in eclipse view "Maven Repositories".
The resource is unvailable to be linked by other projects of a different workspace. is there a way having "maven install" to put shnapshots to the "top" local repository available for any project?
or do i missunterstand the concept?
Workspace projects is a just a convenience feature provided by the m2e plugin where it resolves the dependencies to projects in the current workspace if the artifact specification (group id, artifact id and version) matches that of a project in the workspace. If there are no matches, m2e just uses the jar in the .m2/repo folder as the dependency.
The benefit of this feature is that you don't have to maven build and install the dependency projects continuously, your code changes are reflected immediately in the dependent project.
However, this is just a convenience feature and you can always do a maven install in a dependency project and refresh the dependent project to get the change reflected there.
TL;DR just do a usual maven install on your dependency project and refresh any workspace. It should work.

Dependency and workspace projects

I have a Maven project called Utils that i'm working on. I also have another project, called A, that uses classes of Utils. So, I've added a dependency to Utils in the POM of A. I precise that the two projects are not installed in the local repository (or another private repository). When I try to package the project A, I get an error because Maven tries to get the Utils project from the local repository and central repository, but it's not there. I don't want to install the project because it's not final, i don't want to give it a version because there is no release.
Thanks
It's safe to install the project into local repository. Just use mvn install in the Utils' project folder. Anytime you do install it will be replaced by newest in your local repo.
But don't deploy it, it means others could use it. In comparison, your local repo is used only by you.
It seems that the Maven plugin on Eclipse provides this possibility. And there is no need to install the artifacts corresponding to the active projects in the local repository. It seems that the plugin considers the workspace as a second local repository (you can see this using the Maven repositories view). First, the Workspace resolution feature must be enabled (Right click on the project then under Maven). When I want to run the project, I use Run configurations wizard, and Resolve workspace must be checked.
Is it a good solution? I don't know if it just seems to work or if it really works.
Thanks