void (@NotNull Collection<? extends DataNode<E>> toCreate, @NotNull IdeModifiableModelsProvider modelsProvider) { for (DataNode<E> module : toCreate) { Module created = createModule(module, modelsProvider); module.putUserData(MODULE_KEY, created); // Ensure that the dependencies are clear (used to be not clear when manually removing the module and importing it via external system) final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(created); RootPolicy<Object> visitor = new RootPolicy<>() { @Override public Object visitLibraryOrderEntry(@NotNull LibraryOrderEntry libraryOrderEntry, Object value) { modifiableRootModel.removeOrderEntry(libraryOrderEntry); return value; } @Override public Object visitModuleOrderEntry(@NotNull ModuleOrderEntry moduleOrderEntry, Object value) { modifiableRootModel.removeOrderEntry(moduleOrderEntry); return value; } }; for (OrderEntry orderEntry : modifiableRootModel.getOrderEntries()) { orderEntry.accept(visitor, null); } } }