BuildEnvironment (@NotNull ProjectConnection connection, @NotNull ExternalSystemTaskId taskId, @NotNull ExternalSystemTaskNotificationListener listener, @Nullable CancellationToken cancellationToken, @Nullable GradleExecutionSettings settings) { BuildEnvironment buildEnvironment = null; try { ModelBuilder<BuildEnvironment> modelBuilder = connection.model(BuildEnvironment.class); if (cancellationToken != null) { modelBuilder.withCancellationToken(cancellationToken); } if (settings != null) { final String javaHome = settings.getJavaHome(); if (javaHome != null && new File(javaHome).isDirectory()) { modelBuilder.setJavaHome(new File(javaHome)); } } // do not use connection.getModel methods since it doesn't allow to handle progress events // and we can miss gradle tooling client side events like distribution download. GradleProgressListener gradleProgressListener = new GradleProgressListener(listener, taskId); modelBuilder.addProgressListener((ProgressListener)gradleProgressListener); modelBuilder.addProgressListener((org.gradle.tooling.events.ProgressListener)gradleProgressListener); modelBuilder.setStandardOutput(new OutputWrapper(listener, taskId, true)); modelBuilder.setStandardError(new OutputWrapper(listener, taskId, false)); buildEnvironment = modelBuilder.get(); if (LOG.isDebugEnabled()) { try { String version = buildEnvironment.getGradle().getGradleVersion(); LOG.debug("Gradle version: " + version); if (GradleVersion.version(version).compareTo(GradleVersion.version("2.6")) >= 0) { LOG.debug("Gradle java home: " + buildEnvironment.getJava().getJavaHome()); LOG.debug("Gradle jvm arguments: " + buildEnvironment.getJava().getJvmArguments()); } } catch (Throwable t) { LOG.debug(t); } } } catch (Throwable t) { LOG.warn("Failed to obtain build environment from Gradle daemon.", t); } return buildEnvironment; }