15
  • 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?

OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87

5 Answers5

32

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
philomath
  • 2,209
  • 6
  • 33
  • 45
Shirishkumar Bari
  • 2,692
  • 1
  • 28
  • 36
6

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.)

Bjørn Vester
  • 6,851
  • 1
  • 20
  • 20
  • OK it's not, it says: `JVM: 1.8.0_265 (Private Build 25.265-b01)` but can I change it now? or should I uninstall gradle and install it again?? – OrenIshShalom Oct 01 '20 at 17:12
  • This is not about Gradle but rather your JDK installation. You have to make sure your JAVA_HOME environment variable is set correctly. I see that you are using Ubunto which, depending on how you installed Java, manages this for you. Run `echo $JAVA_HOME` to see what it is set to. If it is wrong, try running `update-java-alternatives -l` to list the Java installations, and `sudo update-java-alternatives -s [NAME]` to set it to a particular version. If this does not work, try looking for the variable in `/etc/environment`, `~/.bashrc`, `~/.profile` or similar places. – Bjørn Vester Oct 01 '20 at 23:15
  • No `JAVA_HOME` in any of the mentioned places ... I have absolutely no clue how can gradle find another java version, when I called `update-java-alternatives -l` there was only one (11) java version – OrenIshShalom Oct 02 '20 at 03:55
2

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

1
  • 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

OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
  • 1
    I think you are right that it was Gradle issue after all. But from the link you gave, it is actually Ubuntu that is to blame. From what I can read, Ubuntu has a custom distribution of Gradle where they change the start-up script to redefine `JAVA_HOME`. (I assume you installed it through the package manager.) When you instead downloaded 6.7-rc-3 from the official servers, you got a vanilla distribution without this weird behavior. I wonder why the Ubuntu folks have done that... :/ – Bjørn Vester Oct 02 '20 at 08:35
0

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

agent {
    label 'openjdk11'
}
bradyb
  • 1
  • 2