0

The Gradle project I'm trying to build is from this example on GitHub. (per the README, I'm running the exec.sh script).

I am trying to build a Gradle Docker image on my MacBook Pro (Big Sur v 11.6.6), but as many other SO entries mentioned, I keep getting this common error:

> #7 0.301 ERROR: JAVA_HOME is set to an invalid directory: /opt/java/openjdk
> #7 0.301 
> #7 0.301 Please set the JAVA_HOME variable in your environment to match the
> #7 0.301 location of your Java installation.

However, I've set JAVA_HOME to an entirely different value, and when I echo it on my terminal, I get that correct value:

echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home

And

/usr/libexec/java_home       
/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home

I've gone through all the SO entries on this, and the solution is usually to set the JAVA_HOME variable to the correct value. However, in this case, I've successfully set that variable.

My shell is:

echo $SHELL
/bin/zsh

So I added JAVA_HOME to .zshrc as well.

Why, then, does Gradle keep telling me I'm using a different value? I've been Googling this error all today, and have not found this precise situation.

NOTE: I did read Gradle finds wrong JAVA_HOME even though it's correctly set, but that's for Ubuntu, and the suggested fixes didn't work.

I also added a "gradle.properties" to the root of my project and added the following line, but that didn't help either:

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home

The output I get from running "exec.sh" is:

sh exec.sh
[+] Building 1.0s (8/8) FINISHED                                                
 => [internal] load build definition from Dockerfile                       0.0s
 => => transferring dockerfile: 119B                                       0.0s
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 117B                                          0.0s
 => [internal] load metadata for docker.io/library/gradle:7.4.2-jdk11      0.6s
 => [1/4] FROM docker.io/library/gradle:7.4.2-jdk11@sha256:66e99844e0687a  0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 14.03kB                                       0.0s
 => CACHED [2/4] WORKDIR /tmp                                              0.0s
 => CACHED [3/4] ADD . /tmp                                                0.0s
 => ERROR [4/4] RUN gradle build                                           0.3s
------
 > [4/4] RUN gradle build:
#8 0.286 
#8 0.286 ERROR: JAVA_HOME is set to an invalid directory: /opt/java/openjdk
#8 0.286 
#8 0.286 Please set the JAVA_HOME variable in your environment to match the
#8 0.286 location of your Java installation.
#8 0.286 
------
executor failed running [/bin/sh -c gradle build]: exit code: 1
Unable to find image 'auth0/[IMAGENAME]:latest' locally
docker: Error response from daemon: pull access denied for auth0/[IMAGENAME], repository does not exist or may require 'docker login': denied: requested access to the resource is denied.
See 'docker run --help'.

I can also confirm that I can run the app outside of Docker, so that is where I'm making a mistake.

Aphorism44
  • 67
  • 11
  • would you mind providing full output from exec.sh? BTW, I do believe those code samples won't work in docker env: master branch uses spring boot 2.7.0 which is not compatible with gradle 6.5 – Andrey B. Panfilov Jun 26 '22 at 04:24
  • 1
    If this is in a Docker context, the Docker image has its own Java installation and its own environment; it sees neither the JDK on your host nor the `$JAVA_HOME` environment variable you have set. Do you have the image's Dockerfile, or any other source code required to demonstrate the issue? – David Maze Jun 26 '22 at 10:17
  • @AndreyB.Panfilov I updated as requested. One thing - I did update the Dockerfile to the below to try and version it correctly: FROM gradle:7.4.2-jdk11 – Aphorism44 Jun 26 '22 at 20:54

0 Answers0