boolean (final Project myProject, final RunConfiguration configuration, final ExecutionEnvironment env, final boolean ignoreErrors, final boolean forceMakeProject) { if (!(configuration instanceof RunProfileWithCompileBeforeLaunchOption runConfiguration)) { return true; } //noinspection deprecation if (runConfiguration.isExcludeCompileBeforeLaunchOption() || (configuration instanceof RunConfigurationBase && ((RunConfigurationBase<?>)configuration).excludeCompileBeforeLaunchOption())) { return true; } final Ref<Boolean> result = new Ref<>(Boolean.FALSE); try { final Semaphore done = new Semaphore(1); ApplicationManager.getApplication().executeOnPooledThread(() -> { if (!myProject.isDisposed()) { final ProjectTaskManager projectTaskManager = ProjectTaskManager.getInstance(myProject); final Pair<ProjectTaskContext, ProjectTask> pair; try { pair = ReadAction.nonBlocking(() -> { final ProjectTask projectTask; if (forceMakeProject) { // user explicitly requested whole-project make projectTask = projectTaskManager.createAllModulesBuildTask(true, myProject); } else { final Module[] modules = runConfiguration.getModules(); if (modules.length > 0) { for (Module module : modules) { if (module == null) { LOG.error("RunConfiguration should not return null modules. Configuration=" + runConfiguration.getName() + "; class=" + runConfiguration.getClass().getName()); } } final Ref<Boolean> includeTests = new Ref<>(true); // use the biggest scope by default if (configuration instanceof JavaRunConfigurationBase) { // use more fine-grained compilation scope avoiding compiling classes, not relevant for running this configuration final JavaRunConfigurationBase conf = (JavaRunConfigurationBase)configuration; final String runClass = conf.getRunClass(); final JavaRunConfigurationModule confModule = conf.getConfigurationModule(); if (runClass != null && confModule != null) { DumbService.getInstance(confModule.getProject()).runWithAlternativeResolveEnabled(() -> { try { includeTests.set((JavaParametersUtil.getClasspathType(confModule, runClass, false, true) & JavaParameters.TESTS_ONLY) != 0); } catch (CantRunException ignored) { } }); } } projectTask = projectTaskManager.createModulesBuildTask(modules, true, true, true, includeTests.get()); } else if (runConfiguration.isBuildProjectOnEmptyModuleList()){ projectTask = projectTaskManager.createAllModulesBuildTask(true, myProject); } else { projectTask = new EmptyCompileScopeBuildTaskImpl(true); } } ProjectTaskContext context = new ProjectTaskContext(ExecutionManagerImpl.EXECUTION_SESSION_ID_KEY.get(env), configuration); env.copyUserDataTo(context); return Pair.create(context, projectTask); }).expireWith(myProject).executeSynchronously(); ProjectTaskManagerImpl.putBuildOriginator(myProject, CompileStepBeforeRun.class); projectTaskManager.run(pair.first, pair.second).onSuccess(taskResult -> { if ((!taskResult.hasErrors() || ignoreErrors) && !taskResult.isAborted()) { result.set(Boolean.TRUE); } }).onProcessed(taskResult -> done.up()); } catch (ProcessCanceledException e) { done.up(); } } else { done.up(); } }); done.waitFor(); } catch (Throwable e) { return false; } return result.get(); }