void () { ApplicationManager.getApplication().runWriteAction(() -> { try { for (Module module : ModuleManager.getInstance(getProject()).getModules()) { ModuleRootManager rootManager = ModuleRootManager.getInstance(module); ModifiableRootModel model = rootManager.getModifiableModel(); for (OrderEntry orderEntry : model.getOrderEntries()) { model.removeOrderEntry(orderEntry); } model.commit(); } } catch (Throwable e) { e.printStackTrace(); // when running test from within IDEA it would fail because junit.jar cache is locked by host IDEA instance } }); }