org.gradle.tooling.GradleConnectionException: 无法获取 'BuildEnvironment' 类型的模型

org.gradle.tooling.GradleConnectionException: Could not fetch model of type 'BuildEnvironment'

我在 windows 上 运行 使用最新版本的 Gradle 宁 netbeans 任何时候我尝试 select 来自 gradle 任务的旧项目面板我收到以下错误:

Requested project: D:\ian\libGDX\MarioBros

Stack trace:
    org.gradle.tooling.GradleConnectionException: Could not fetch model of type 'BuildEnvironment' using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.10-all.zip'.
        at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:55)
        at org.gradle.tooling.internal.consumer.ExceptionTransformer.transform(ExceptionTransformer.java:29)
        at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:41)
        at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor.run(DefaultAsyncConsumerActionExecutor.java:57)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        at java.lang.Thread.run(Thread.java:748)
        at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
        at org.gradle.tooling.internal.consumer.DefaultModelBuilder.get(DefaultModelBuilder.java:50)
        at org.netbeans.gradle.project.model.DefaultGradleModelLoader.loadModelWithProgress(DefaultGradleModelLoader.java:551)
        at org.netbeans.gradle.project.model.DefaultGradleModelLoader.access00(DefaultGradleModelLoader.java:64)
        at org.netbeans.gradle.project.model.DefaultGradleModelLoader.run(DefaultGradleModelLoader.java:419)
        at org.netbeans.gradle.project.tasks.GradleDaemonManager.runNonBlockingGradleTask(GradleDaemonManager.java:35)
        at org.netbeans.gradle.project.tasks.GradleDaemonManager.access0(GradleDaemonManager.java:22)
        at org.netbeans.gradle.project.tasks.GradleDaemonManager.execute(GradleDaemonManager.java:125)
        at org.jtrim.concurrent.AbstractTaskExecutorService$FunctionWrapper.execute(AbstractTaskExecutorService.java:270)
        at org.jtrim.concurrent.AbstractTaskExecutorService$TaskOfAbstractExecutor.execute(AbstractTaskExecutorService.java:340)
        at org.jtrim.concurrent.Tasks$RunOnceCancelableTask.execute(Tasks.java:342)
        at org.jtrim.concurrent.SingleThreadedExecutor$QueuedItem.runTask(SingleThreadedExecutor.java:919)
        at org.jtrim.concurrent.SingleThreadedExecutor$QueuedItem.access00(SingleThreadedExecutor.java:898)
        at org.jtrim.concurrent.SingleThreadedExecutor$Impl$Worker.executeTask(SingleThreadedExecutor.java:815)
        at org.jtrim.concurrent.SingleThreadedExecutor$Impl$Worker.processQueue(SingleThreadedExecutor.java:827)
        at org.jtrim.concurrent.SingleThreadedExecutor$Impl$Worker.run(SingleThreadedExecutor.java:861)
        at org.jtrim.concurrent.SingleThreadedExecutor$Impl.run(SingleThreadedExecutor.java:453)
        at java.lang.Thread.run(Thread.java:748)
    Caused by: org.gradle.api.GradleException: Java home supplied via 'org.gradle.java.home' is invalid. Invalid directory: C:\Program Files\Java\jdk1.8.0_92
        at org.gradle.launcher.cli.converter.PropertiesToDaemonParametersConverter.convert(PropertiesToDaemonParametersConverter.java:51)
        at org.gradle.tooling.internal.provider.ProviderConnection.initParams(ProviderConnection.java:172)
        at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:91)
        at org.gradle.tooling.internal.provider.DefaultConnection.getModel(DefaultConnection.java:168)
        at org.gradle.tooling.internal.consumer.connection.CancellableModelBuilderBackedModelProducer.produceModel(CancellableModelBuilderBackedModelProducer.java:53)
        at org.gradle.tooling.internal.consumer.connection.PluginClasspathInjectionSupportedCheckModelProducer.produceModel(PluginClasspathInjectionSupportedCheckModelProducer.java:41)
        at org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection.run(AbstractConsumerConnection.java:58)
        at org.gradle.tooling.internal.consumer.connection.ParameterValidatingConsumerConnection.run(ParameterValidatingConsumerConnection.java:46)
        at org.gradle.tooling.internal.consumer.DefaultModelBuilder.run(DefaultModelBuilder.java:60)
        at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.run(LazyConsumerActionExecutor.java:84)
        at org.gradle.tooling.internal.consumer.connection.CancellableConsumerActionExecutor.run(CancellableConsumerActionExecutor.java:45)
        at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConsumerActionExecutor.run(ProgressLoggingConsumerActionExecutor.java:58)
        at org.gradle.tooling.internal.consumer.connection.RethrowingErrorsConsumerActionExecutor.run(RethrowingErrorsConsumerActionExecutor.java:38)
        at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor.run(DefaultAsyncConsumerActionExecutor.java:55)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
        at org.gradle.internal.concurrent.ManagedExecutorImpl.run(ManagedExecutorImpl.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
        ... 1 more

还有其他人 运行 遇到过这个错误吗?以及如何解决这个问题?

实际上这里已经描述了这个问题

Caused by: org.gradle.api.GradleException: Java home supplied via 'org.gradle.java.home' is invalid. Invalid directory: C:\Program Files\Java\jdk1.8.0_92

如果您转到 gradle.properties 配置文件,您将获得以下内容

org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_92

您可以将其删除或提供原始 JAVA_HOME 位置。希望能解决您的问题。

N.B: 如果你的路径没问题,那么在你的路径中像上面那样使用双反斜杠“\”。

%userprofile%\.gradle\gradle.properties 中的错误 jdk 版本导致了我的问题。另一种尝试方法是直接在 gradle_dir/bin/gradle.bat 中硬编码 java 主路径,如下所示:

set JAVA_HOME="c:\Program Files\Java\jdk1.8.0_251"

这可能是一个 proxy 问题,请尝试创建包含以下内容的 %userprofile%\.gradle\gradle.properties~/.gradle/gradle.properties :

systemProp.http.proxyHost=[host]
systemProp.http.proxyPort=[port]
systemProp.http.proxyUser=[user]
systemProp.http.proxyPassword=[pass]
systemProp.https.proxyHost=
systemProp.https.proxyPort=
systemProp.https.proxyUser=
systemProp.https.proxyPassword=
systemProp.http.nonProxyHosts=localhost|orther.domain.tld