Why is New->Project From Existing Source worthless?


This has been bugging me for years and curiosity has finally gotten the best of me. If you create a project with File->New->Project From Existing Source the resulting project only shows any "src" folder. But doesn't show other directories. This is vastly different behavior that File->New->Project which results in a project that shows all sub-directories.

For example if you have a layout like this:

-project directory

If you use Project from existing source the project view in intellij will only show the "src/" directory.

However, if you use New->Project and select the directory that has sources in it you get a project where project view shows all the directories.

Why? What is the point of Project from Existing Sources if it results in a project that doesn't show all the other directories?


Project created with File->New->Project... (then pointing at the existing directory):

Project create with File->New->Project from Existing Sources (this view is worthless):


It looks like Java files are several levels below your project root. In this case Java module is created one level above of the default package and the content root becomes `src` instead of `etl`. If the default package is directly under `src`, `etl` will be used as the content root.

It's really hard for the IDE to know which folder you want to be the content root of the module since there are many possible layouts for the projects. Automatic configuration doesn't know how many top level directories in the hierarchy you want to be included in the module content, therefore it defaults to one level above the default package directory.

If your project is using a different layout, you should create the new project with the appropriate module and specify the content/source roots manually.

So, Project from Existing Sources option should be used for the most basic projects, like when the default package is just one level below.


Why does File->New->Project... always work regardless of project layout? 

This is a constant trouble point for people moving to IntelliJ. I have been using IntelliJ since 2004ish so I know that the "existing sources" option is worthless and to always use the New->Project option. However, for someone just coming to IntelliJ, when they have checked out sources from version control manually and then want to create a project, the "existing sources" option seems the most intuitive. They get really confused when the project doesn't show the other directories and I have to constantly guide them to the New->Project option 

You can fix a project created with "existing sources" by going to File->Project Structure->Sources Tab and delete the current Content Root, then select your top-level directory as the root. However, a new user won't know this, nor should they have to know this. It should just work.

IMHO, if I select "~/temp/etl" as the directory containing the existing sources then "~/temp/etl" should be the top-level directory and everything underneath it should be in the project.



Please sign in to leave a comment.