private static void prepareTaskState(@NotNull ExternalSystemTaskId id,
                                       @NotNull GradleExecutionSettings settings,
                                       @NotNull ExternalSystemTaskNotificationListener listener) {
    if (ExternalSystemExecutionAware.hasTargetEnvironmentConfiguration(settings)) return; // Prepared by TargetBuildLauncher.

    RunConfigurationTaskState taskState = settings.getUserData(RunConfigurationTaskState.getKEY());
    if (taskState == null) return;

    LocalTargetEnvironmentRequest request = new LocalTargetEnvironmentRequest();
    TargetProgressIndicator progressIndicator = TargetProgressIndicator.EMPTY;
    try {
      taskState.prepareTargetEnvironmentRequest(request, progressIndicator);
      LocalTargetEnvironment environment = request.prepareEnvironment(progressIndicator);
      String taskStateInitScript = taskState.handleCreatedTargetEnvironment(environment, progressIndicator);
      if (taskStateInitScript != null) {
        writeAndAppendScript(settings, taskStateInitScript, "ijtgttaskstate");
      }
    }
    catch (ExecutionException e) {
      throw new RuntimeException(e);
    }
    listener.onEnvironmentPrepared(id);
  }
private static void prepareTaskState(@NotNull ExternalSystemTaskId id,
                                       @NotNull GradleExecutionSettings settings,
                                       @NotNull ExternalSystemTaskNotificationListener listener)