I"m going to have to re-organize my directory/folder structure in order to use git with Eclipse, since repo's are not supposed to be located within the workspace.
Being a git newbie I'd like some confirmation that my intended structure makes sense before I start re-organizing and init'ing repos.
My current workspace includes an Android project, a GAE/J project, some common code shared between them. Aside from some 3rd party libraries, my projects are closely related so I'm going to put them into a single repo.
Here is my proposed structure:
root_dir/
workspace/
.metadata
.git (<--- main git repo for my projects)
GAE_Project/
.project
src/war/etc.
Android_prject/
.project
src/bin/etc.
Shared_Code_Project/
.project
src/etc.
3rd_Party_Lib_Project/
.git (<--- has its own repo)
.project
src/bin/etc.
Based your proposed structure, it would seem that all the projects under workspace is in one repository. Your proposed structure is fine with one caveat that I can see. You may have to ignore the third party project because it is located under workspace (which is the Git repository).
Eclipse projects do not necessarily have to be located within the workspace directory. It can be located anywhere on your system. It may be better to place the third party projects in a different directory.
As long as your repos are outside of your workspace, it doesn't matter where they are relative to the workspace. In your example root_dir contains the workspace and your projects, and I wanted to point out that the workspace could be at /some/random/path and your projects could be /at/totally/different/path, it shouldn't matter where they are relative to each other.
I keep my local repos in ~/dev/git/ in unix and /c/dev/git in Windows.
I keep my workspaces wherever Eclipse wants me to keep them, which is the first directory it pops up for me, sometimes ~/Documents/workspace, or %USERDIR%\workspace. Usually I don't even know where my workspace is, and it doesn't really matter, because the important and interesting part is where my code is.
Related
Hello so I'm working on a Java project for a class, using Intellij. My teacher does not want an SRC folder or anything else that Intellij makes on the Github Repo. Would it be possible to initialize a git repository in the SRC? or would it create problems for Intelj
There are several possibilities to approach this problem:
Create the git-repository in a separate folder. Note though that this approach is a bit tricky to get right! There are actually two options for this:
git --work-tree=<project-location>/src to use git from a separate directory.
git --git-dir=<rep-location> to use the specified location for the repository. This will require you to use --git-dir every time.
Initialize the repository inside the src-folder. This one for sure is ugly, but IntelliJ shouldn't care at all about any non-java files during compilation and if it still complains you could even exclude the directory from being compiled
Use a .gitignore-file to exclude files from VCS. This would leave the src-folder in the repository, but apart from that you can exclude any file you feel like from being versioned. (See the official documentation and #CrazyCoders answer for more details on this)
Do something funny with symlinks. I.e. create the repository somewhere else, place a symlink in the src-folder and use the repository via the symlink.
Check this page. You can exclude IntelliJ IDEA project files (.idea directory and .iml files from the version control).
Here is the sample .gitignore for IntelliJ IDEA projects that you can adjust for your needs.
How can I make sure a project that is shown in my workspace is actually part of the workspace. Below, I will explain what happened so that you know why I'm asking this question.
I had checked out a project into my workspace, and then had configured it as a Maven project by selecting Configure->Convert to Maven Project; in most cases, when I do this, the project becomes part of the workspace. But in this case it hadn't. But I spent a few hours before realizing that I need to import the project in order for the workspace to recognize it as workspace project. So, I want to avoid this situation and be able to look at a flag or file or something that tells me if a project that is shown in the Eclipse window is actually a workspace project.
Thanks
I'm adding the following to make the problem more clear:
This is what I do; I have a workspace with a few projects (all Java/Maven project); everything works. Then I checkout another project from svn into the workspace; so, the folder of the new project is within the same workspace. I expected that as soon as I check out the new project into the workspace, and convert the new project into a Maven project, then the new project be recognized by Eclipse as one of the projects in the workspace. But that is not the case; I actually have to import it.
The project folder is there, and I can see it in the Project explorer. Nothing happens to it, but it is not used by the workspace. For example, if I add breakpoints to the Java files which are in the new project, they are not used. At this point, I use File->Import menu to import the project from the same folder that is already in the workspace, and bang, it starts working, and my breakpoints work.
Is my procedure for checking out a project from SVN into the workspace wrong? I want to fix my procedure to make sure this will never happen. Do you think that even though the new project is a subfolder of workspace, I should still need to import the project into the workspace?
I just noted another fact; this particular project that I'm importing is a Maven multi-module; could it be that the parent project is actually part of the workspace, but the modules inside it are not; therefore, just because it is a Maven multi-module, I need to import the sub-modules.
There are four ways to create a project in Eclipse:
create
Create in a default location (workspace folder on a filesystem)
Create in user-specified location (anywhere)
import
Project is referenced from workspace, untouched otherwise, location on a filesystem is unchanged
Project is copied into default location
You probably want to know if a project is located in workspace folder on filesystem. To do this, you can open project's properties and find location in resource node:
"... in order for the workspace to recognize it as a workspace project..." doesn't make any sense to me. I'm not exactly an eclipse expert, but a workspace is the set of directories in which you are working at one time in eclipse. There can be more than one workspace for eclipse on a given machine.
If you checked it out and it appeared in eclipse, then it was "in the workspace" afaik. Now, Maven tasks create and change files, and those changes do not automatically show up in the workspace -- you have to refresh the project, which essentially syncs the filespace with the workspace.
If that doesn't cover your case, then detail what you mean by "not in the workspace".
I have a rather big project with about 30 seperate subprojects hosted on subversion. If I want to set up the project on a new client, i have to check out 30 projects (each time manually selecting the trunk), then change the eclipse facette for each project and then convert every project into a plugin project. Finally I have to build the project using maven.
Is there an easier way to do this? Perhaps some kind of API provided by eclipse which allows me to change project settings without fiddling with the .settings and .classpath files?
It sounds to me that you are missing some of the project metadata files from your source control system. There should be no reason for performing these steps every time you pull down these projects.
Check to make sure that all files starting with '.' in project root are in source control along with the entire contents of the .settings directory.
I know why not to commit Eclipse/IDE-specific files into a VCS like Git (which I am actually using). That is one of the reasons I am using Maven and having it generating these files for you and not having them under version control.
But I wonder, if these files should be ignored in .gitignore which itself is under control of VCS/Git:
.classpath
.project
.settings/
target/
Is this okay?
What are the pros and cons since the .gitignore file itself becomes kind of IDE-specific as the files ignored there are IDE-spefific? Any best-practice?
With the team's I've worked on, the general rule has been that you don't check in anything that is generated by or obtained by Maven. Since the pom.xml contains everything you need to create the .project, .classpath, and .settings files, we don't check them in.
My .gitignore always contains .classpath, .settings, .project, and target for Maven projects.
Edit: As mentioned in my comment below, here is another suggestion: If you really want to avoid having Maven or IDE specific entries in your .gitignore, try writing your .gitignore so you list only what you DO want checked in.
*
!stuffIDoWantToCheckIn
I'm getting my information from the following article: https://help.github.com/articles/ignoring-files
That suggests that you can create a global gitignore file (suggest under ~/.gitignore_global) containing .project, etc. As the file is outside the repo, it won't show...
You register it as a global ignore file with the following command:
git config --global core.excludesfile ~/.gitignore_global
Alternatively, you can create a per-repo untracked gitignore entries in the .git/info/exlude file
I agree on not putting the IDE files under version control, this occasionally causes all sorts of pains, and as you mentioned using maven renders this unnecessary as any developer can simply import the project from the POM and get going
If these files are not put in the .gitignore they can easy be checked in by mistake
furthermore I do not find listing them in the .gitignore makes it IDE specific, you can list project files of eclipse, IntelliJ IDEA, and Netbeans, all in the same .gitignore if your team members use a mix of different IDEs. Over time you may accumulate a template .gitignore that ignores project files from all IDEs used in your team(s) to use whenever you create a new repository
If you are totally against putting these in the project .gitignore you can put them in the users .gitignore, but that in my mind is a bit looser as it depends on the individual development machines being configured correctly, and also these need to be maintained to be kept in sync with any new additions
Edit: I currently have an equivalent .hgignore, same concept different syntax, I converted it to git as an example of such a .gitignore file
/target/
/bin/
/build/
/.classpath
/.project
/.settings/
/.checkstyle
/atlassian-ide-plugin.xml
/.idea/
/*.iml
/*.ipr
/*.iws
*.orig
*.swp
*~
usually .project and .settings/ should likley be versioned and ignored!
.classpath and target should not be versioned but ignored.
This is a first inital boot-up on checkout-practice.
i.e.
You told everone to use four spaces as tab, this information is stored under .settings/xxx
but you give no restriction where they have to install their tomcat/jdk's (stored under .classpath)
ok?
I run into this obstacle when my debugger steps into some classfile
without corresponding source. Finding it is often difficult:
You have to search for the site hosting the respective project,
and find its ``download source'' page (for instance, last time I searched
for the JPA API, and it took me hours to obtain the sources). Or, you might
be required to check it out from revision control.
You need to know the exact version you are using. Otherwise
the debugger might step into comments and empty lines :)
There is no convention for packaging source code—some
projects include it in the jar itself; some provide a separate zip file;
others put it in a src/ subfolder within the zip.
I know Maven has the capability of downloading source from its repository and
including it in the src paths when an IDE config file is generated. But
Maven's repo is so poor in terms of content—few libs actually have
their source uploaded.
Why is it so complicated when it can be made straightforward? We could have
some central repo which relates a classfile (or a hash thereof) to the source
file it was compiled from (or a link to it). Maybe a rather huge repo, but
pretty simply structured. An IDE plugin could query it to fetch what's needed automatically.
Have you, guys, experienced the same?
How do you obtain the sources to attach?
Both m2eclipse and IDEA will download the sources and javadocs for any dependencies. The m2eclipse sources can be downloaded by right-clicking on a dependency (or the whole project if you want all sources) and clicking Maven->Download Sources.
On newer versions of m2eclipse you can also automatically download sources by going to Window->Preferences...->Maven, then selecting the "Download Artifact Sources" option. When you open a type in a dependency jar that there are currently no sources available for, Maven will download the sources in the background and update the source attachment in the background.
Haven't seen a satisfactory solution myself.
I tend to roll my own repo, without Maven (Maven is fine, but it doesn't click with me). I run something similar to the BSD ports system, that is, one big structured tree that contains little Ant build files. These build files either checkout the source of a project, pull its dependencies from somewhere else in the tree and build it (these are for the projects I want to build- i.e., mine) or pull binaries from somewhere else (which might be an external source or my own binaries repository).
The system could easily be extended to pull src jars, but I do that manually now.
it may be complicated but it is worth the initial effort.
i do it the following way:
in my project directory i have three major directories,
src (my own)
lib
suppl (sources / javadocs when no sources exist)
i put in suppl one zip file per library, containing the sources. in intellij this gives me not only debugger superpowers, but also javadocs.
you are right, obtaining the sources is a pain. sometimes the sources come deliveded in the .jar file of the lib, sometimes as a seperate download (my favorite) and sometimes i have to create a seperate cvs/svn dir where i can checkout the sources. i usually need to re-package them the way i like them, even if provided in a zip.
i am sceptical about maven. i just don't like to hand over my decisions about choosing libs to a program.
we do something similar to Andreas. Our lib directory has subdirectories categorizing further. One such sub dir is source or debug which has the source JAR/ZIPs of all the jars that we want to debug. Do it once and you're good. We use an IVY repository for the jars and source jars.
This is all done automatically if you use M2eclipse (http://m2eclipse.sonatype.org).