我在安装了3.2.1
的MacOS X 10.12.1上运行Gradle brew install gradle
,我自己没有设置任何env变量等,尝试使用Java 9 EA:
gradle build -Dorg.gradle.java.home=~/jdk-9.jdk/Contents/Home
但构建失败
失败:构建因异常而失败。
- 出了什么问题:无法启动守护程序进程。此问题可能是由守护程序的错误配置引起的。例如, 使用了无法识别的jvm选项。
据我所知,它失败了,因为守护进程试图使用maxpermsize JVM选项(Java 8+不支持,但在Java 8中它只是一个警告)。
所以我试图禁用该守护进程:
mkdir -p ~/.gradle && echo "org.gradle.daemon=false" >> ~/.gradle/gradle.properties
但gradle build
仍在尝试启动守护程序...我删除了项目目录中的~/.gradle
和.gradle
。还有其他想法吗?
$ gradle build -Dorg.gradle.daemon=false -Dorg.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/3.2.1/userguide/gradle_daemon.html.
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 guide chapter on the daemon at https://docs.gradle.org/3.2.1/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
FAILURE: Build failed with an exception.
* What went wrong:
java.lang.ExceptionInInitializerError (no error message)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
> Starting Daemon%
答案 0 :(得分:0)
好的我知道了,因为我正在运行我的构建:
import random
welcome_phrase = "Hi there. What's your name?"
print("{:s}".format(welcome_phrase))
user_name = input("Name: ")
print("Hey {:s}, I am Crash. Let's play a game. I am thinking of a number between 1 and 20. Can you guess the number?".format(user_name))
attempts = 5
secret_num = random.randint(1,20)
for attempt in range (attempts):
guess = int(input("Guess the number: "))
if guess > secret_num:
print("Your guess is higher than the number. Try again")
elif guess < secret_num:
print("Your guess is lower than the number. Try again.")
else:
print("Well done! {:d} is the right number.".format(guess))
print("It took you {:d} attempts.".format(attempt))
break
if guess != secret_num:
print("Sorry, you have used up all your chances.")
print("The number was {:d}".format(secret_num))
Gradle必须生成一个新线程,以使用与JAVA_HOME指向的Java版本不同的Java版本。这是通过使用该Java版本生成一个守护程序线程(尽管有gradle build -Dorg.gradle.java.home=~/jdk-9.jdk/Contents/Home
选项)并且失败来完成的。如果我明显地将JVM args传递给构建,也会发生同样的情况。
解决方法是在终端false
中设置JAVA_HOME,然后运行export JAVA_HOME=~/jdk-9.jdk/Contents/Home
。
仍然无法工作,因为最新的Java9版本打破了Gradle的反思,但那是一个不同的故事。
答案 1 :(得分:0)
我在这里发帖,因为它的评论太大了(但肯定不是答案)。
如果您使用 - debug 运行脚本,您将看到基础错误。我是通过java-9直接运行它而不设置JAVA_HOME顺便说一句。
我有同样的问题,一些jdk-9构建回来并用以下方法解决:
set _JAVA_OPTIONS "-Dsun.reflect.debugModuleAccessChecks=true
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
--add-opens=java.base/java.lang.invoke=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util.concurrent=ALL-UNNAMED
--add-opens=java.base/java.text=ALL-UNNAMED"
设置而不是导出,因为我正在使用fish,但应该以相同的方式为bash工作。
有趣的是,这仍然会因为构建153而失败:
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private final java.util.Map java.util.Collections$UnmodifiableMap.m accessible: module java.base does not "opens java.util" to unnamed module @67080771
但是这是在_JAVA_OPTIONS中指定的。这可能是构建153的回归。