I am unable to run ./gradlew build on linux Alma ...
# community-support
m
I am unable to run ./gradlew build on linux Alma Webserver . Getting error -
> Task :compileJava FAILED
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'.
Could not find tools.jar. Please check that /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b08-2.el8.x86_64/jre contains a valid JDK installation.
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.6.4/userguide/command_line_interface.html#sec:command_line_warnings BUILD FAILED in 1s 1 actionable task: 1 executed
c
Have you done as the error message suggests, confirming that you have a valid JDK installation, and if not installing the JDK?
m
yes valid JDK.
c
Looks like a JRE, not a JDK:
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b08-2.el8.x86_64/jre
m
means ?
c
JRE is the Java Runtime Environment, for running Java applications; for developing (compiling, etc) Java application you need to have the Java Development Kit (JDK) installed.
m
Yes
Actually when run ./gradlew build then getting
c
./gradlew
does not execute any tasks, hence won’t hit that error that came from the
compileJava
task. Install a JDK (or use a Gradle Toolchain) and you’ll be good.
…and use a recent Gradle version
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
m
have Gradle
8.7
c
the error message indicates otherwise.
m
java -version openjdk version "1.8.0_412" OpenJDK Runtime Environment (build 1.8.0_412-b08) OpenJDK 64-Bit Server VM (build 25.412-b08, mixed mode)
c
that’s your JRE, not Gradle. Also very dated, current LTS is Java 21.
1
m
Yes I know actually I am working on a project . Client gave me 1.8
Gradle 5.6.4
c
you should consider upgrading the Gradle version, and the JVM version if there are no constraints.
1
a
yeah completely agree...there's a lot of new gradle functionality for build optimization you aren't currently able to benefit from
plus that's a 10 year old runtime
m
okay. I am not more familiar. Can you please how upgrade in linux
c
You’ll want to walk through these guides for each major version (6,7,8), ensuring things work at each step along the way.
for the JDK you can install the latest using that OS’ package manager (don’t know what linux flavor that is)
m
Now that is solved but now error is coming - ./gradlew build ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b08-2.el8.x86_64 Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
What should be valid directory ?
c
if the JDK install didn’t set JAVA_HOME itself then you can set it to the base directory of where the JDK is installed. Generally one level above
bin/java
m
Same error with path /usr/lib/jvm
c
Try
which java
to see if that helps locate where its installed.
m
I have frsh install java version "22.0.1" 2024-04-16 but still error is coming ./gradlew build FAILURE: Build failed with an exception. * What went wrong: Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Exception java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache [in thread "Daemon worker"]
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 822ms
a
did you try running it with any of the stacktrace, info or debug options like suggested?
v
Start with using a supported Java version. There is no Gradle version supporting running on 22: https://docs.gradle.org/current/userguide/compatibility.html