IDEA Plugin Dev - Module ( API )

Card Puncher Data Processing


Working with Modules in a plugin


The IntelliJ Platform provides a number of Java classes and interfaces you can use to work with modules within the project and core API

Class Class Type API / Model
ModuleManager Abstract class Project
Module Interface Core
ModuleRootManager Abstract class Project
ModuleRootModel Interface Project
ModuleUtil Utility Lang
ModifiableModuleModel Interface Project
ModifiableRootModel Interface Project

Module Manager: Manage the Module (list of modules, …)

Use the ModuleManager.getModules() method.

Module: Dependencies and classpath of a module

Order entries: 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();

ModuleRootManager: SDK

Use the ModuleRootManager.getSdk() method. This method returns a value of the Sdk type.

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();

ModuleRootManager: Module dependency between Module

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();

See also: IDEA Plugin Dev - Dependency

Use the ModuleManager.getModuleDependentModules(module) method to get a list of modules that depend on this module

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);

ModuleUtil: To get a module to which the specified file or PSI element belongs

  • File: To get the project module to which the specified file belongs, use the ModuleUtil.findModuleForFile() static method.
java 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();
  • psi To get the project module to which the specified PSI element belongs, use the ModuleUtil.findModuleForPsiElement(psiElement) method.

Library (Order Entry) How do I work with libraries available within a module?

To get the list of libraries available within a module, use OrderEnumerator.forEachLibrary method. IDEA Plugin Dev - Order Entry (SDK, Library, Module dependencies)

// This sample code outputs a list of libraries for the module 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");

Discover More
Idea Project Model Dev
IDEA Plugin Dev - Facet

facet in Plugin Dev context. A Facet is a configuration unit of a module. Use the following class from the Idea Lang API: com/intellij/facet/FacetManagerFacetManager and com/intellij/facet/FacetFacet...
Card Puncher Data Processing
IDEA Plugin Dev - Order Entry (SDK, Library, Module dependencies)

Order entries include: SDK, (By default, all modules uses the project SDK) libraries and other modules the module uses. With the IntelliJ IDEA UI, you can view order entries for a module on...
Idea Project Model Dev
IDEA Plugin Dev - Project

from a plugin dev point of view A project consists of one or several modules. Each module includes the plugin source code Each module includes order entries that refer to SDK and libraries...

Share this page:
Follow us:
Task Runner