void (@NotNull Project project, @NotNull RunConfiguration configuration, @NotNull Artifact artifact) { RunManagerEx runManager = RunManagerEx.getInstanceEx(project); final List<BuildArtifactsBeforeRunTask> buildArtifactsTasks = new ArrayList<>(runManager.getBeforeRunTasks(configuration, ID)); if (runManager.getBeforeRunTasks(configuration, ID).isEmpty()) { //Add new task if absent BuildArtifactsBeforeRunTask task = new BuildArtifactsBeforeRunTask(project); buildArtifactsTasks.add(task); List<BeforeRunTask> tasks = new ArrayList<>(runManager.getBeforeRunTasks(configuration)); tasks.add(task); runManager.setBeforeRunTasks(configuration, tasks); } for (BuildArtifactsBeforeRunTask task : buildArtifactsTasks) { task.setEnabled(true); task.addArtifact(artifact); } }