Setting Project specific maven repository - eclipse

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

Related

Using a separated source folder from SVN on Eclipse

So, here in the company we work with svn, and our svn server only have the source folder. When I use NetBeans, it's everything ok because I can add source folders in project and will work fine in svn. But on eclipse if i do the checkout from command line and add that folder in my dynamic web project, I can't see the svn history and nothing, svnclipse just does not work on that folder.
Our structure of the projects it's something like this
Workspace
Project folder
Project1
Project configuration files
SourceCode
Packages
Project folder 2
Project2
SourceCode
I already try to make checkout using svnclipse, but he add alot of extra config files, he turns the folder in a project and the source folder is add as a link to another project, in this scenario the svnclipse quick diff does not work properly.
There is a way to use that folder as source and Svnclipse works on that ?
Sorry if my English is not so good
There is no easy way to do what you want. In Eclipse a source control provider can only be connected to the project itself. So options are:
Use another svn client like command line or TortoiseSVN.
Create a small SVN project with the Eclipse project configuration files that also use svn:externals to pull in your source folder from repository.
With option 2, you would checkout this small SVN project from some other repository using Subclipse in Eclipse, could even be a local file:// repository and then the svn:externals property would also cause your source folder to be checked out.

How do I link an IntelliJ IDEA project to a local git repository?

I'm new to IntelliJ and trying to switch from Eclipse to IntelliJ.
In Eclipse it's done by creating a workspace and then importing the local repository. The workspace is separate from the repository. The workspace only reference the repository.
I want to do this in IntelliJ. I think the setup would be something like the project located in e.g. C:\Projects\MyProgram\ with MyProgram having .idea in it. The actual code for MyProgram would be in e.g. C:\Repos\MyProgram.git. The repository would only contain code, not config files for the IntelliJ project. Alternatively I'd like to know how this is typcially done with IntelliJ.
Typically this is done1 as follows:
git clone your repo (if you don't already have it locally).
In Intellij, open or import the root repo folder as a project.
Add .idea/ (or *.iml as appropriate) to your .gitignore file.
I'm not sure if there's a good reason for trying to keep the IntelliJ files in a different part of your filesystem.2 Some of the advice out there regarding Eclipse concerns the semantics of workspaces, which don't exist in IntelliJ.
1. To be more precise, this is how I typically do it :)
2. Although I'm happy to be convinced otherwise!
You can specify a different content root in the "More Settings" while creating a project. This location is the one where you have your repository.

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 connect/sync just the src folder of the maven project in eclipse workspace to src folder in repository

I have commited just the src folder and pom.xml of maven project into SVN repository in order to make it independent of IDE (As .settings, .project etc are files specific to eclipse ide)
Then when I'm trying to import the src folder in a newly created maven project (as it has the other files which are needed to run the project in eclipse), basically I only want to synchronize the src folder and pom.xml with the repository, I get a warning while I import the src folder 'as a folder in existing project' AS 'Destination project is detached from the source control. So please take into consideration that the plug-in won't provide any SVN actions for these resources' and then I'm not able to use Compare with and Team Options. It doesn't even show the revision no. besides the imported class files and folders.
Is there a way to do this ??
What is/are the usual industry practice/s ??
There're 2 options.
1.) Check out the SVN files using some other tool e.g. (TortoiseSVN) and then import the maven project using 'Materialize Maven Project'. This will create necessary metadata for eclipse and will also maintain the version info for the checked out project. See this reference http://www.sonatype.com/books/m2eclipse-book/reference/creating-sect-importing-projects.html
2.) The (better) other way is to download 'Maven SVN Integration' plugin using update site
http://m2eclipse.sonatype.org/sites/m2e-extras/. Once you install the plugin, you would be able to see option 'Check out as Maven Project' in SVN repository exploring perspective.
Thanks,
Prabhjot

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.