module root model changes only on module initialization?

I'm trying to manage module dependencies from a plugin, accoring to external spec.

I'm using LibraryTablesRegistrar model to add libraries to project:

final LibraryTablesRegistrar libTablesRegistrar = LibraryTablesRegistrar.getInstance();
final LibraryTable libraryTable = libTablesRegistrar.getLibraryTable(module.getProject());
final LibraryTable.ModifiableModel libTableModel = libraryTable.getModifiableModel();
library = libTableModel.createLibrary(libraryName);
libraryModel.addRoot(jarPath, OrderRootType.CLASSES);

and then I'm using module root manager to add these libraries to module:
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
final ModifiableRootModel moduleRootModel = moduleRootManager.getModifiableModel();
final Library lib = libraryTable.getLibraryByName(libraryName);
if (moduleRootModel.findLibraryOrderEntry(lib) == null) {

This works when I place it in initComponent() of my module component, but not in runtime, say, when I'm doing that in filesystem listener (i would like to update libraries as dependency definition changes)

Is it possible to do it in "runtime"?

Please sign in to leave a comment.