在Linux上使用Java 10的最新Gradle版本时,它无法将Java的版本号标识为10作为有效的Java版本。如何在Linux机器上解决这个问题?记录错误here
的详细信息这是完整的错误报告(N.B.正在运行gradle --version
或gradle -v
也会提供相同的输出:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
编辑:
输出gradle --stacktrace
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10'.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
java.lang.IllegalArgumentException: Could not determine java version from '10'.
at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:70)
at org.gradle.api.JavaVersion.current(JavaVersion.java:80)
at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:32)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:174)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:60)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:37)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
输出java --version
java 10 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)
答案 0 :(得分:5)
您需要升级Gradle。 4.5.1及更高版本肯定支持Java 10。
如果您认为自己已经安装了4.5.1或更高版本,但gradle -version
仍然无法运行,那么当您在命令行输入gradle
时,它可能是&{} #39;由于某种原因,它仍在运行旧版本。
一个常见的事情是别名gradle
到./gradlew
,因此在Gradle项目的上下文中,您将使用包装器Gradle而不是系统Gradle。这通常很有帮助,但在这种情况下,它会适得其反。您应该能够使用which
确定已安装的系统Gradle:
> which gradle
/usr/local/bin/gradle
> $(which gradle) -version
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
(我已经忽略了一些关于非法反思访问的警告,如果你得到那些,请不要担心它们。)
如果$(which gradle) -version
仍然无法运行,则需要升级系统gradle。但如果确实如此,要更新Gradle包装器,您可以编辑build.gradle
-
task wrapper(type: Wrapper) {
gradleVersion = '4.6'
}
- 然后使用系统Gradle重新运行wrapper
任务:
> $(which gradle) wrapper
Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 7s
1 actionable task: 1 executed
> ./gradlew -version
Downloading https://services.gradle.org/distributions/gradle-4.6-bin.zip
......................................................................
[etc.]
------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------
Build time: 2018-02-28 13:36:36 UTC
Revision: 8fa6ce7945b640e6168488e4417f9bb96e4ab46c
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM: 10.0.1 ("Oracle Corporation" 10.0.1+10)
OS: Mac OS X 10.13.4 x86_64
答案 1 :(得分:2)
获取ppa的帮助并升级您的gradle版本,Ubuntu 17带有gradle sudo apt install gradle
将安装默认的gradle版本。
升级java 10需要在命令下运行。
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt upgrade gradle
答案 2 :(得分:0)
伙计我在这种情况下发现了问题。我在官方debian存储库中安装了gradle,其中包含一个过时版本的gradle,它不支持Java 10.从official site下载并安装Gradle并将其软链接到/ usr / bin / gradle,它运作得很好。所以问题主要是从debian存储库安装gradle,这些存储库目前已经过时了。