终端下执行 Gradle 命令出错
date
Jan 31, 2023
slug
something error gradle
status
Published
tags
问题
summary
type
Post
问题 Log 及相关信息
Starting a Gradle Daemon (subsequent builds will be faster)
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.8.3/userguide/gradle_daemon.html
Process command line: /Users/jiangjiwei/Library/Java/JavaVirtualMachines/corretto-11.0.16.1/Contents/Home/bin/java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED -Xmx1536m -Dfile.encoding=UTF-8 -Duser.country=CN -Duser.language=zh -Duser.variant -cp /opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/jiangjiwei/.cargo/bin:/Users/jiangjiwei/Library/Application Support/JetBrains/Toolbox/scripts:/Users/jiangjiwei/Library/Android/sdk/tools/:/Users/jiangjiwei/Library/Android/sdk/platform-tools/:/opt/homebrew/bin/php:/Users/jiangjiwei/flutter/bin:/Users/jiangjiwei/.gradle/wrapper/dists/gradle-6.8.3-all/6czipnbiesy2sl92ioo8dht91/gradle-6.8.3/lib/gradle-launcher-6.8.3.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 6.8.3
Please read the following process output to find out more:
-----------------------
错误: 找不到或无法加载主类 org.gradle.launcher.daemon.bootstrap.GradleDaemon
原因: java.lang.ClassNotFoundException: org.gradle.launcher.daemon.bootstrap.GradleDaemon
问题原因
未知
可能复现的场景
解决方案
方案1:
将环境变量中
JAVA_HOME
配置为特殊的路径,例如 1.8 或 Java 11 等。此方案,可以一劳永逸的解决所有的本地项目终端执行问题,但与现有全局 JAVA 版本出现冲突时,不便使用。
方案2:
在项目中新建
gradle.properties
文件,然后添加以下配置:org.gradle.java.home=java_home
此 java_home 不是全局的,可以对单个项目配置。
方案3:
可在终端中临时设置
JAVA_HOME
环境变量。# Windows
set JAVA_HOME=C:\.....
# macOS
export PATH=$PATH:~/Library/Java/JavaVirtualMachines/corretto-11.0.16.1/Contents/Home
仅本次的终端执行有效,本次执行环境关闭「当前终端 Tab 关闭或当前终端应用关闭」后失效。