You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2026/06/27 05:13:17 UTC

(groovy) branch master updated: GROOVY-12108: Provide a more informative error message when GROOVY_HOME is not set correctly

This is an automated email from the ASF dual-hosted git repository.

paulk-asert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new 568bf980df GROOVY-12108: Provide a more informative error message when GROOVY_HOME is not set correctly
568bf980df is described below

commit 568bf980dfd617c3e98d62b51ce38d74e9ae3490
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jun 27 15:13:08 2026 +1000

    GROOVY-12108: Provide a more informative error message when GROOVY_HOME is not set correctly
---
 src/bin/startGroovy     | 20 ++++++++++++++++++++
 src/bin/startGroovy.bat | 22 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/src/bin/startGroovy b/src/bin/startGroovy
index 9d6971b406..2412dd8eac 100644
--- a/src/bin/startGroovy
+++ b/src/bin/startGroovy
@@ -163,6 +163,26 @@ if [ -z "$GROOVY_CONF" ] ; then
 fi
 STARTER_CLASSPATH="$GROOVY_HOME/lib/@GROOVYJAR@"
 
+# Sanity check: the Groovy startup jar must exist, otherwise the JVM fails later
+# with a cryptic "Could not find or load main class ...GroovyStarter". This most
+# commonly happens when GROOVY_HOME is set but points at the wrong location.
+if [ ! -f "$STARTER_CLASSPATH" ] ; then
+    warn "Could not find the Groovy startup jar:"
+    warn "    $STARTER_CLASSPATH"
+    warn ""
+    if [ -n "$GROOVY_HOME" ] ; then
+        warn "GROOVY_HOME is set to: $GROOVY_HOME"
+        warn "but it does not look like a valid Groovy installation"
+        warn "(no lib/@GROOVYJAR@ found under it)."
+    else
+        warn "GROOVY_HOME is not set and could not be derived from the script location."
+    fi
+    warn ""
+    warn "Please either unset GROOVY_HOME, or set it to the root directory of your"
+    warn "Groovy installation (the directory containing the bin, conf and lib folders)."
+    die  "Aborting."
+fi
+
 # Create the final classpath. Setting a classpath using the -cp or -classpath option means not to use the
 # global classpath. Groovy behaves then the same as the java interpreter
 if [ -n "$CP" ] ; then
diff --git a/src/bin/startGroovy.bat b/src/bin/startGroovy.bat
index 2e3c8b4ea6..068f017c74 100644
--- a/src/bin/startGroovy.bat
+++ b/src/bin/startGroovy.bat
@@ -259,6 +259,28 @@ set CMD_LINE_ARGS=%$
 @rem Setup the command line
 set STARTER_CLASSPATH=%GROOVY_HOME%\lib\@GROOVYJAR@
 
+@rem Sanity check: the Groovy startup jar must exist, otherwise the JVM fails later
+@rem with a cryptic "Could not find or load main class ...GroovyStarter". This most
+@rem commonly happens when GROOVY_HOME is set but points at the wrong location.
+if not exist "%STARTER_CLASSPATH%" (
+    echo.
+    echo ERROR: Could not find the Groovy startup jar:
+    echo     %STARTER_CLASSPATH%
+    echo.
+    if not "%GROOVY_HOME%" == "" (
+        echo GROOVY_HOME is set to: %GROOVY_HOME%
+        echo but it does not look like a valid Groovy installation
+        echo ^(no lib\@GROOVYJAR@ found under it^).
+    ) else (
+        echo GROOVY_HOME is not set and could not be derived from the script location.
+    )
+    echo.
+    echo Please either clear GROOVY_HOME ^(set GROOVY_HOME=^), or set it to the root
+    echo directory of your Groovy installation ^(the directory containing the bin,
+    echo conf and lib folders^).
+    goto end
+)
+
 if exist "%USERPROFILE%/.groovy/init.bat" call "%USERPROFILE%/.groovy/init.bat"
 
 @rem Setting a classpath using the -cp or -classpath option means not to use