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

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.

Related

How to check out multiple maven projects from remote git repository

after a couple of hours trying and reading a number of tutorials, I can't fix the following problem: I have a remote server running a git repository. From eclipse (neon.2 and egit) I pushed several maven projects, each with its own pom.xml to this repository. When a friend of mine, who wants to co-develop tries to setup his environment, also using Eclipse Neon.2 and egit, we are not able to reproduce the setup in the Package Explorer. We get all the sources but in one project. The original maven projects are all nested in this one project. This wrong setup results in a couple of problems when trying to compile or run the projects.
We used File-> Import-> Git-> Projects from Git-> Clone URI. In Source Git Repository we pointed the Repository path to /home/git/workspace.git. In the Branch Selection dialog we can then only see the master. In the following Local Destination dialog we checked the Clone submodules checkbox. We played around with the following options to run wizards which were all failing, so we ended up with this one project option in the bottom of the three options in the dialog.
What is not happening, is the import projects dialog as explained here https://wiki.eclipse.org/EGit/User_Guide/Remote#Import_Projects
(but this seems to be a former version, since the Clone submodules checkbox is missing in the dialog before on this web page)
Can anybody please tell us how to extract the maven projects as top elements in eclipse, linked to the existing git repository, such that we can work as a team?
Should you need any additional information, please let me know.
Thank you in advance.
I would advise you to always put all Eclipse configuration files to the repository when creating projects. What you should do is add all necessary maven integration related files to the repository (.project, .classpath, .settings/*m2e.core.prefs or better yet entire .settings). If you have done so, you are fine. If not, add them and pull changes on your colleague's machine.
On target machine remove the project from workspace, but do not delete contents. In Eclipse Git repositories view select your repository and expand to see Working tree. Right click it and select Import projects. This will trigger the flow you pointed our at Eclipse wiki. From there it should be straightforward - Eclipse will try to detect projects and will import them, so that they have Maven nature and are managed by EGit.
If you don't want to or cannot share maven configuration in the repository, have a look at this answer which tries to describe how to achieve that without Eclipse configuration files.

What is the difference between maven update and maven build?

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

Jenkins build after Eclipse commit on SVN

I'm using Jenkins for CI, I'm trying to establish a build strategy. My point here is to build
after every commit. I saw that I need to create post-commit file in the hooks directory of my
project repository.
The porblem is that I'm using SVN as an Eclipse plugin, so I don't really have a repository,
I'm just using "right click -> Team " on my project to synchronize/update/commit ...
I can't see where to create my post-commit file in order to launch a Jenkins build.
Does anyone kow how to deal with this issue ?
I've seen many posts before, but none of them was helpful !
Thanks
The simplest solution is to use Poll SCM in your Jenkins job and have it look for changes e.g. every 5 minutes. It won't trigger the build instantly on commit, but it will decouple your SVN and Jenkins a bit more.

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

How to automatically change Eclipse build path when I check out Git branches

I'm using Eclipse Helios and EGit 0.11.3.
I have a project where different branches use different versions of some of the libraries on my Java build path. For example, branch_old uses foo_lib_v1.0.jar while branch_new uses foo_lib_v2.0.jar.
If I'm working on branch_new and I need to checkout branch_old to test something, it's a bit of a hassle: I must manually reconfigure the build path in Eclipse before the project can build successfully.
Is there a way to store Eclipse's Java build path configuration for my project in git, so that when I check out a branch the build path is automatically modified? If not, is there another way to achieve the same result?
Thanks.
I see several choices here:
store project files (.classpath and .project) in Git as part of your branch. This way you would have to store all your dependencies in Git too, which is a hassle if you have a lot of them.
use Maven (m2eclipse plugin) and store project definition (pom.xml) file as part of your version control. Maven will greatly simplify your project dependency configuration
More information on m2eclipse plugin can be found at http://www.sonatype.com/books/m2eclipse-book/reference/
Should work: Put the .buildpath under version control. So its checkouted every time you switch the branches.
AFAIK Eclipse stores his build classpath in a file like .classpath(?) You can just add the file to git and have an own config for each branch.
Define several user libraries in your workspace, such as FooLib1, FooLib2, FooLib2. Then in the project's build path at a given branch reference the appropriate version of the library. Make sure you include project metadata files such as .classpath in your git repository and you should be set.