This document is a work in progress. Please post comments or questions on our dedicated forum.

This topic considers the concept of IntelliJ IDEA projects and related subjects, such as modules, facets, libraries, SDK.
The project structure and Java classes you can use to manage projects and modules have been considered.

Project and Its Components

This section briefly discusses the IDEA project structure, project components and related terms. For more information about projects and their components, refer to Project , Module , Library , and Facet in IntelliJ IDEA Web Help.


In IntelliJ IDEA, a project encapsulates all your source code, libraries, build instructions into a single organizational unit. Everything you do in IntelliJ IDEA, is done within the context of a project. A project defines some collections referred to as modules and libraries. Depending on the logical and functional requirements to the project, you can create a single-module or a multi-module project.


A module is a discrete unit of functionality that can be run, tested, and debugged independently. Modules includes such things as source code, build scripts, unit tests, deployment descriptors, etc. In the project, each module can use a specific SDK or inherit SDK defined on the project level (see the SDK section later in this document). A module can depend on other modules of the project.


A library is an archive of compiled code (such as JAR files) that your modules depend on. IntelliJ IDEA supports three types of libraries:

For more information about libraries, refer to Library .


Every project uses a Software Development Kit (SDK). For Java projects, SDK is referred to as JDK (Java Development Kit). SDK determines which API library is used to build the project. If your project is multi-module, the project SDK by default is common for all modules within the project. Optionally, you can configure individual SDK for each module.
For more information about SDKs, see JDKs and Configuring Project JDK in IntelliJ IDEA Web Help.


A facet represents certain configuration, specific for a particular framework/technology, associated with a module. A module can have multiple facets. E.g. Spring specific configuration is stored in a Spring facet.
For more information about facets see Facet and Facet Dependencies in IntelliJ IDEA Web Help.

Project Structure

From the plugin developer's point of view, a project can be thought of as follows:

A project consists of one or several modules. Each module includes the plugin source code and so called order entries that refer to SDK and libraries the module uses. By default, all modules uses the project SDK. In adition, a module can optionally have a set of facets.
This document explains how you can explore and change the structure of projects using API.

Working with Projects

This section explains how to complete some common tasks related to management of projects. The Java classes and interfaces that you can use to explore and change the project contents are discussed.

How to Work with Project Files?

IntelliJ IDEA stores the project configuration data in XML files. The list of those files depends on the plugin project format .

For file-based format projects, the information core to the project itself (e.g. location of the component modules, compiler settings, etc.) is stored in the <%project name%>.IPR file. The information about modules the project includes is stored in <%module name%>.IML files. Module files are created for each module.

For directory-based format projects, the project and workspace settings are stored in a number of XML files under the <%Project home directory%>/.idea directory. Each XML file is responsible for its own set of settings and can be recognized by its name: projectCodeStyle.xml, encodings.xml, vcs.xml etc. As for the file-based format projects, .IML files describe modules.

To work with projects and project files, you can use the following classes and interfaces:

Note that you don't need to access project files directly to load or save settings. See Persisting State of Components for more information.

Note that hereafter, the project variable is of the Project type. For example, for the opened project, you can get it from an action: Project project = e.getProject();

How do I get a list of source roots for all modules in my project?

Use the ProjectRootManager.getContentSourceRoots() method. To clarify this, consider the following code snippet:

String projectName = project.getName();
StringBuilder sourceRootsList = new StringBuilder();
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots();
for (VirtualFile file : vFiles) {

Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties");

How do I check whether a file is related to a project?

IntelliJ IDEA provides the ProjectFileIndex interface you can use to verify whether a file or directory is related to the specified IDEA project.
This section explains how you can use this interface.

How do I get an instance of the ProjectFileIndex interface?

Use the ProjectRootManager.getFileIndex() method. For example:
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();

How do I get a module to which a file belongs?

To determine a module in the project in question to which the specified virtual file belongs, use the ProjectFileIndex.getModuleForFile(virtualFile) method:
Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(virtualFile);
Note that this method returns null if the file does not belong to any module.

You can also use the ProjectFileIndex.getContentRootForFile method to get the module content root to which the specified file or directory belongs:

VirtualFile moduleContentRoot = ProjectRootManager.getInstance(project).getFileIndex().getContentRootForFile(virtualFileorDirectory);

How do I get the module source root or library source root to which the specified file or directory belongs?

Use the ProjectFileIndex.getSourceRootForFile method. For example:
VirtualFile moduleSourceRoot = ProjectRootManager.getInstance(project).getFileIndex().getSourceRootForFile(virtualFileorDirectory);
Note that this method returns null if the file or directory does not belong to any source root of modules in the project.

How do I check whether a file or directory is related to the project libraries?

The ProjectFileIndex interface implements a number of methods you can use to check whether the specified file belongs to the project library classes or library sources.
You can use the following methods:

How do I get the project SDK?

How do I set the project SDK?

Note that by default, the project modules use the project SDK. Optionally, you can configure individual SDK for each module.

Working with Modules

IntelliJ IDEA provides a number of Java classes and interfaces you can use to work with modules:

This section discusses how to complete some common tasks related to management of modules.

How do I get a list of modules the project includes?

Use the ModuleManager.getModules() method.

How do I get dependencies and classpath of a module?

Order entries include SDK, libraries and other modules the module uses. With the IntelliJ IDEA UI, you can view order entries for a module on the Dependencies tab of the Project Structure dialog box.
To explore the module dependencies , use the OrderEnumerator class.

The following code snippet illustrates how you can get classpath (classes root of all dependencies) for a module:

VirtualFile[] roots = ModuleRootManager.getInstance(module).orderEntries().classes().getRoots();

How do I get the SDK the module uses?

Use the ModuleRootManager.getSdk() method. This method returns a value of the Sdk type.
The following code snippet illustrates how you can get detailed information on SDK the specified module uses:

ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
Sdk SDK = moduleRootManager.getSdk();
String jdkInfo = "Module: " + module.getName() + " SDK: " + SDK.getName() + " SDK version: "
                    + SDK.getVersionString() + " SDK home directory: " + SDK.getHomePath();

How do I get a list of modules on which this module directly depends?

Use the ModuleRootManager.getDependencies() method to get an array of the Module type values or the ModuleRootManager.getDependencyModuleNames() to get an array of module names. To clarify, consider the following code snippet:

ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
Module[] dependentModules = moduleRootManager.getDependencies();
String[] dependentModulesNames = moduleRootManager.getDependencyModuleNames();

How do I get a list of modules that depend on this module?

Use the ModuleManager.getModuleDependentModules(module) method.

Note that you can also check whether a module (module1) depends on another specified module (module2) using the ModuleManager.isModuleDependent method in the following way:
boolean isDependent = ModuleManager.getInstance(project).isModuleDependent(module1,module2);

How do I get a module to which the specified file or PSI element belongs?

String pathToFile = "C:\\users\\firstName.LastName\\plugins\\myPlugin\src\";
VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(pathToFile);
Module module = ModuleUtil.findModuleForFile(virtualFile,myProject);
String moduleName = module == null ? "Module not found" : module.getName();

How do I work with libraries available within a module?

How do I get a list of libraries available within a module?

To get the list of libraries, use OrderEnumerator#forEachLibrary method. To clarify this, consider the following code snippet that illustrates how to output the list of libraries for the specified module:

final List<String> libraryNames = new ArrayList<String>();
ModuleRootManager.getInstance(module).orderEntries().forEachLibrary(new Processor<Library>() {
    public boolean process(Library library) {
       return true;
Messages.showInfoMessage(StringUtil.join(libraryNames, "\n"), "Libraries in Module");

This sample code outputs a list of libraries for the module module.

How do I get the library content?

The Library class provides the getUrls method you can use to get a list of source roots and classes the library includes. To clarify, consider the following code snippet:

StringBuilder roots = new StringBuilder("The " + lib.getName() + " library includes:\n");
for (String each : lib.getUrls(OrderRootType.SOURCES)) {
for (String each : lib.getUrls(OrderRootType.CLASSES)) {
Messages.showInfoMessage(roots.toString(), "Library Info");

In this sample code, lib is of the Library type.

How do I get a set of facets the module includes?

Use the FacetManager and Facet classes.

to be continued