Intellij Idea: shared sources between projects

Often enough you will need to share the source code between two or more Java projects. In Eclipse, this is very intuitive. Under the build path settings you just link the appropriate paths.
Due to several problems with Eclipse, I prefer to use Intellij Idea. Unfortunately, this was not as intuitive in Intellij Idea and took me some time to figure out.

Let’s assume you have two projects: Project A and Project B. Project A is independent of project B and compiles from its own sources, whereas project B shares some of its source code with project A.
IntelliJ employs the concept of modules, a project can compose of several modules (of several projects in Eclipse-speak). To make the aforementioned scenario work, you must create a project that includes the two modules (create a module from existing sources for both project A and project B). In project A, you mark the source folders that you require as source folders (blue folder icon).
In module B, you create a module dependency for project A. And that’s it!

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a comment