Table of Contents

IDEA Plugin Dev - Project

About

IDEA - Project from a plugin dev point of view

Structure

Idea Project Model Dev

Configuration Project File (.ipr)

The project configuration data files depends on the plugin project format.

Project API

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.

Project

For example, to get the opened project, you can get it from an action:

Project project = e.getProject();

ProjectRootManager: List of source roots for all modules

String projectName = project.getName();
StringBuilder sourceRootsList = new StringBuilder();
VirtualFile[] vFiles = ProjectRootManager.getInstance(project).getContentSourceRoots();
for (VirtualFile file : vFiles) {
  sourceRootsList.append(file.getUrl()).append("\n");
}
Messages.showInfoMessage("Source roots for the " + projectName + " plugin:\n" + sourceRootsList, "Project Properties");

ProjectFileIndex: Is a file belongs to a project / module ?

The ProjectFileIndex interface is used to verify whether a file or directory is related to the specified IDEA project.

ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
Module module = projectFileIndex.getModuleForFile(virtualFile);
VirtualFile moduleContentRoot = projectFileIndex.getContentRootForFile(virtualFileorDirectory);
VirtualFile moduleSourceRoot = projectFileIndex.getSourceRootForFile(virtualFileorDirectory);

Project SDK

Get

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

Set

Documentation / Reference