void () { ApplicationManager.getApplication().runWriteAction(() -> { final Module moduleA = createModule("a.iml"); final Module moduleB = createModule("b.iml"); myModuleRootListener.assertEventsCount(2); final Sdk jdk; final Sdk jdkBBB; jdk = ProjectJdkTable.getInstance().createSdk("AAA", JavaSdk.getInstance()); ProjectJdkTable.getInstance().addJdk(jdk, getTestRootDisposable()); myModuleRootListener.assertNoEvents(); jdkBBB = ProjectJdkTable.getInstance().createSdk("BBB", JavaSdk.getInstance()); ProjectJdkTable.getInstance().addJdk(jdk, getTestRootDisposable()); myModuleRootListener.assertNoEvents(); ProjectRootManager.getInstance(myProject).setProjectSdk(jdkBBB); myModuleRootListener.assertNoEvents(true); final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel(); final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel(); rootModelA.inheritSdk(); rootModelB.inheritSdk(); ModifiableRootModel[] rootModels = {rootModelA, rootModelB}; ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel()); myModuleRootListener.assertEventsCount(1); ProjectRootManager.getInstance(myProject).setProjectSdk(jdk); myModuleRootListener.assertEventsCount(1); final SdkModificator sdkModificator = jdk.getSdkModificator(); sdkModificator.addRoot(getTempDir().createVirtualDir(), OrderRootType.CLASSES); sdkModificator.commitChanges(); myModuleRootListener.assertEventsCount(1); }); }