M2Eclipse: Automatically execute Maven when pom.xml changes? - eclipse

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?

Related

Add dependency to git project in Eclipse

I am not able to find an answer to this question: How is it possible to make an project dependend on a git project in Eclipse? I am only able to find answers on this topic for maven projects or jar files.
Specifically, i am trying to make my project dependent on this git project. I was able to import it Eclipse, the src folder and everything inside it is shown correctly.
But i am not able to add it as dependency to my project, simply because Eclipse does not show the project in its dialogs. How is one supposed to add such projects?

maven publish jar to .ivy

I have a maven project, which will produce a jar file, and I want to use it in another sbt project. Is there any method to publish the jar file to .ivy rather than in .m2?
I try to put the jar file in the libs under the sbt project, but it does not work. and use the mvn install the jar to the .m2 does not work too.
As I understand it you have a maven project and an SBT project. The SBT project depends on the artifact produced by your maven project.
You ask how to publish the maven produced artifact to your local .ivy so it can be picked up by the SBT project.
you can probably achieve that using an ant task in the maven build.
However I'd like to suggest different angles :
Make the sbt project aware of the local .m2
Simply add resolvers += Resolver.mavenLocal to your sbt build definition, if you don't want to pollute the main build definition, add that line to a local.sbt file alongside the main build defition. SBT merges all the .sbt files found at the project root.
Publish to a controlled repository
This is especially useful if you want the build to be easily reproduceable outside of your local machine.
The idea is simply to publish the maven project to an actual server, either an internal nexus/artifactory server for proprietary code or to a public artefact hosting (such as bintray)
I use bintray all the time to publish custom builds of opensource projects while I wait for PRs to be merged in master and published an the official build.
Add your artifact server as a resolver to the SBT project and you are good to go :)

SVN Checkout of multi module maven project causing build issues

I am trying to learn how to setup multi-module maven project and share it with colleagues using SVN.
We work with eclipse IDE.
Here is how my project structure looks in SVN.
Each module has its own svn labels and tag trunk, branches, tags etc.
I check out all the modules individually by right clicking on them and choosing check out.
Finally I get the below in my eclipse project explorer:
Here is my pom for the parent project. and this throws errors when I do a mvn clean install
I want to understand how to checkout the projects/ modify my pom to get the build successful.
Thanks
You don't want to check out the root folders of your modules in SVN. All you want is the content of the trunk. So right click on the trunk folder and select Check out as.... Check it out as new projects and enable Maven on those project afterwards. Do this with each of your modules and you should be fine.
If you have Maven SVN connectors installed you have an option called Check out as Maven project. This is very comfortable as it does a few steps for you.

Setting Project specific maven repository

I have multiple projects. I want to create different maven repository paths for each project. Means, each project should point to different folder as maven repository (by default C:/Users/USERNAME/.m2 is used as repo).
I know that this may increase the download and same files if used in multiple projects will be downloaded/kept multiple times. But i want to separate out the repository for different projects so that i can bundle the repository along with my project's source code to be shared to the other person. I simply dont want to share my whole m2 repository (of size 2 gb) for a very small project sized 50 mb.
Regards,
Vibhav
You can specify repository location via command line option -Dmaven.repo.local=
I'd have just put a wrapper script to start maven in the project location and specified repository in it (probably pointing to location inside the project for your use case).
Thanks everyone for your comments.
I finally did the following:
Setup each project as a separate workspace in eclipse
Created a separate apache maven folder for each project (actually duplicating the maven home even though i am using same version of maven)
From eclipse workspace, I pointed out the appropriate maven home
configured the repository path (localRepository) in MAVEN_HOME/conf/settings.xml file from default ~./m2/repository to something like MAVEN_HOME/repo
This way, I could get separate maven repositories for each project (or I should say workspace).
Thanks,
Vibhav Agrawal
See the following answer:
Prevent Jenkins from Installing Artifact to Local Maven Repository
In a nutshell use a settings file for each build. Enables you to control both the local repository used for that project, but also other settings like repositories and build profiles.
My solution using Eclipse and Maven is to create new workspace, maven repository and settings.xml replacing the default .m2 repository path.
your new settings.xml
Then, try in Eclipse: Preferences>User Settings and browse your settings.xml
replace the User Settings file

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