gradle无法使用工具链“JDK 8(1.8)”定位到平台:“Java SE 11”。

huangapple go评论72阅读模式
英文:

gradle Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'

问题

我根据安装指南正在构建ghidra。
一切进行得很顺利,直到我到达这一步
一旦我调用$ gradle buildGhidra,我就会得到以下错误:

> 无法使用工具链“JDK 8(1.8)”定位平台:“Java SE 11”

这看起来很奇怪,因为我确实安装了Java 11:

$ java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment(版本 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM(版本 11.0.8+10-post-Ubuntu-0ubuntu118.04.1,混合模式,共享)

我错过了什么吗?

英文:
  • I'm building ghidra according to the installation guide.
    Everything goes fine Until I get here.
  • Once I call $ gradle buildGhidra I get the following error:
> Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)'

This seems weird because I do have java 11:

$ java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)

What am I missing?

答案1

得分: 32

我在尝试通过Intellij使用Gradle构建时遇到了这个问题。

在我的情况下,我安装并在Intellij中配置了两个JDK,JDK1.8和JDK 11。
对于Gradle来说,默认的JVM是采用JDK1.8。
我通过以下步骤解决了这个问题:

  1. 打开Intellij
  2. 进入首选项
  3. 转到“Build, Execution, Deployment” -> “Build Tools” -> “Gradle”
  4. 搜索“Gradle JVM”。将其更改为所需的JVM
  5. 尝试重新构建应用程序
英文:

I got this problem when trying to build using gradle through Intellij.

In my case I had two JDK's JDK1.8 and JDK 11 installed and configured in Intellij.
For Gradle it was taking JDK1.8 as default JVM.
I solved the issue using below steps :

  1. Open Intellij
  2. Go to Preferences
  3. Go to "Build, Execution, Deployment" -> "Build Tools" -> Gradle
  4. Search for "Gradle JVM". Change it to desired JVM
  5. Try to rebuild the app

答案2

得分: 6

Gradle 使用在您的 JAVA_HOME 环境变量中定义的 Java 发行版,它不会查找路径中的 java 可执行文件。因此,请确保此变量指向有效的 JDK 11 路径。您可以通过运行 gradle --version 来验证是否设置正确,例如:

$ echo %JAVA_HOME%
C:\Work\JDKs\jdk-11.0.8+10

$ gradle --version

------------------------------------------------------------
Gradle 6.6
------------------------------------------------------------

Build time:   2020-08-10 22:06:19 UTC
Revision:     d119144684a0c301aea027b79857815659e431b9

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.8 (AdoptOpenJDK 11.0.8+10)
OS:           Windows 10 10.0 amd64

(请注意上面的 JVM 部分。)
英文:

Gradle uses the java distribution defined in your JAVA_HOME environment variable - it does not look at the java executable in your path. So make sure this variable points to a valid JDK 11 path. You can verify if it is set up correctly by running gradle --version, e.g.

$ echo %JAVA_HOME%
C:\Work\JDKs\jdk-11.0.8+10


$ gradle --version

------------------------------------------------------------
Gradle 6.6
------------------------------------------------------------

Build time:   2020-08-10 22:06:19 UTC
Revision:     d119144684a0c301aea027b79857815659e431b9

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.8 (AdoptOpenJDK 11.0.8+10)
OS:           Windows 10 10.0 amd64

(Notice the JVM part above.)

答案3

得分: 2

你是否在使用集成开发环境(IDE)?请确保在你的Gradle设置中,Gradle使用与你的项目相同的Java版本,你可以在IntelliJ中轻松配置此项。详情请参考:https://www.jetbrains.com/help/idea/gradle-jvm-selection.html#jdk_existing_project

英文:

Are you using an IDE? Make sure that in your Gradle settings, Gradle is using the same java version as your project, this can be easily configured in Intellij https://www.jetbrains.com/help/idea/gradle-jvm-selection.html#jdk_existing_project

答案4

得分: 1

  • 原来 gradle 确实 是罪魁祸首。
  • 可能类似于这篇帖子,我升级到了gradle-6.7
  • 然后,在不进行任何JAVA_HOME更改的情况下,运行 gradle-6.7 --version,我得到了:

------------------------------------------------------------
Gradle 6.7-rc-3
------------------------------------------------------------

构建时间:   2020-09-30 19:16:51 UTC
修订版:     836e96a80625c9c48b612e662e3b13bd2e2f4c3b

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) 版本 1.10.8,编译于2020年5月10日
JVM:          11.0.8(Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
操作系统:     Linux 5.4.0-48-generic amd64

这可能“证明”了 gradle 的确是罪魁祸首

英文:
  • It turns out that gradle was after all the one to blame.
  • Probably similar to this post, I upgraded to gradle-6.7.
  • Then, calling gradle-6.7 --version, without any JAVA_HOME change whatsoever, I got:

------------------------------------------------------------
Gradle 6.7-rc-3
------------------------------------------------------------

Build time:   2020-09-30 19:16:51 UTC
Revision:     836e96a80625c9c48b612e662e3b13bd2e2f4c3b

Kotlin:       1.3.72
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
JVM:          11.0.8 (Ubuntu 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OS:           Linux 5.4.0-48-generic amd64

Which probably "proves" gradle is indeed the one to blame

答案5

得分: 0

Jenkinsfile中将我的代理标签更改为openjdk11后,这个错误就被修复了。

agent {
    label 'openjdk11'
}
英文:

Changing my agent label in the Jenkinsfile, to openjdk11 fixed this error for me.

agent {
    label 'openjdk11'
}

huangapple
  • 本文由 发表于 2020年10月1日 18:29:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/64153532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定