diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8a37876249b513e66993553cde15e5e4a7023972..79326c34d47a050c9f01c745074940cb1625ad36 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -12,7 +12,7 @@ cache:
     - .gradle/caches
 
 build:
-  image: openjdk:8
+  image: eclipse-temurin:21
   stage: build
   script:
     - ./gradlew --console=plain --no-daemon assemble fatJar
@@ -21,7 +21,7 @@ build:
       - "/builds/jastadd/relational-rags/build/libs/relast-*.jar"
 
 test:
-  image: openjdk:8
+  image: eclipse-temurin:21
   stage: test
   script:
     - ./gradlew --console=plain --no-daemon --info test
@@ -36,22 +36,20 @@ pages:
     paths:
     - public
   only:
-    - master
     - main
 
 publish:
-  image: openjdk:8
+  image: eclipse-temurin:21
   stage: deploy
   needs:
     - test
   script:
     - "./gradlew publish"
   only:
-    - master
     - main
 
 publish_dev:
-  image: openjdk:8
+  image: eclipse-temurin:21
   stage: deploy
   needs:
     - test
@@ -59,5 +57,4 @@ publish_dev:
     - "./gradlew setDevVersionForCI"
     - "./gradlew publish"
   except:
-    - master
     - main
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8a44f97d5c135c9262f166256036043ad49748be..342aa7d98c0c400a9e5b6d7075a423e437f00d7f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,7 +2,7 @@
 
 To propose a new feature, or to report a bug, first [create an issue][create-issue] and add labels accordingly.
 Working on such issues is done by creating a merge request from the issue page, which 1) creates a new branch to work on, and 2) creates a new WIP merge request for the new branch.
-Once done (and new tests are written to ensure, a bug is really fixed, and the feature does the right thing), the merge request will be accepted and merged into `develop`.
+Once done (and new tests are written to ensure, a bug is really fixed, and the feature does the right thing), the merge request will be accepted and merged into `dev`.
 
 # Creating normal test cases
 
@@ -73,23 +73,23 @@ The test then ensures, that both output grammars are identical.
 Important information:
 
 - Currently, we are publishing to a private Nexus Maven repository only.
-- We are using [git-flow][git-flow], so only new merge requests are considered for releases to appear in the `master` branch.
+- We are using [git-flow][git-flow], so only new merge requests are considered for releases to appear in the `main` branch.
 - The version is set in the configuration file [RelASTVersion.properties][RelASTVersion.properties].
 
 The workflow:
 
-1) Finish your work with the current feature(s) and merge those back in `develop`.
+1) Finish your work with the current feature(s) and merge those back in `dev`.
 1) Choose a new version number `$nextVersion` depending on the introduced changes **following [semantic versioning][semantic-versioning]**.
 1) Create a new release branch named `release/$nextVersion` and switch to this branch.
 1) Set the version number in the config file calling `./gradlew newVersion -Pvalue=$nextVersion`
 1) Commit this change.
 1) (Optional) Build a new jar file calling `./gradlew jar` (this is automatically called in the publish step and only used to test the newly set version number)
 1) Check, if everything works as planned, e.g., version number is picked up when running the application with `--version`, and all test succeed.
-1) Merge the release branch into `master` (using a merge request) and also back into `develop`.
+1) Merge the release branch into `main` (using a merge request) and also back into `dev`.
 1) Delete the release branch.
 1) [Create a new release][create-release]. Choose the following:
     - *Tag name*: the chosen version number
-    - *Create from*: leave the default `master`
+    - *Create from*: leave the default `main`
     - *Message*: "Version " and the chose version number
     - *Release notes*: list the (important) changes compared to the last release, prepend a link to the built jar using the line `[:floppy_disk: publish-relast-poc-$nextVersion.jar](/../../../-/jobs/$jobNumber/artifacts/raw/build/libs/publish-relast-poc-$nextVersion.jar?inline=false)` replacing `$jobNumber` with the `jar` job of the pipeline run after the merge request, and `$nextVersion`
 1) Publish the built jar to the maven repository calling `./gradlew publish`
diff --git a/build.gradle b/build.gradle
index 1fafdb14e6010af678a0ab9e8d42c0d564e63428..1bbe4b9e0d2e1089c87c971a6ee5b12cc4dc521a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -20,12 +20,12 @@ plugins {
     id 'application'
     id 'idea'
     id 'maven-publish'
-    id 'org.jastadd' version '1.14.5'
+    id 'org.jastadd' version '1.15.0'
 }
 
 apply plugin: PreprocessorPlugin
 
-java.toolchain.languageVersion = JavaLanguageVersion.of(8)
+java.toolchain.languageVersion = JavaLanguageVersion.of(21)
 
 ext {
     mainClassName = 'org.jastadd.relast.compiler.Compiler'
@@ -45,12 +45,13 @@ group = 'org.jastadd'
 application.mainClass = "${mainClassName}"
 
 dependencies {
-    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
-    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
-    testImplementation 'org.assertj:assertj-core:3.22.0'
-    testImplementation 'com.fasterxml.jackson.core:jackson-core:2.13.1'
-    testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.13.1'
-    api 'org.jastadd:jastadd:2.3.5'
+    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.3'
+    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.3'
+    testImplementation 'org.assertj:assertj-core:3.26.3'
+    testImplementation 'com.fasterxml.jackson.core:jackson-core:2.18.2'
+    testImplementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
+    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
+    api 'org.jastadd:jastadd:2.3.6'
     api 'net.sf.beaver:beaver-rt:0.9.11'
 }
 
@@ -73,7 +74,7 @@ try {
     throw new GradleException("File ${versionFile} not found or unreadable. Aborting.")
 }
 
-task newVersion() {
+tasks.register('newVersion') {
     doFirst {
         def props = new Properties()
         props['version'] = value
@@ -81,13 +82,13 @@ task newVersion() {
     }
 }
 
-task printVersion() {
+tasks.register('printVersion') {
     doLast {
         println(version)
     }
 }
 
-task setDevVersionForCI() {
+tasks.register('setDevVersionForCI') {
     doFirst {
         def props = new Properties()
         props['version'] = version + "-$System.env.CI_PIPELINE_IID"
@@ -97,7 +98,7 @@ task setDevVersionForCI() {
 
 jar.archiveBaseName = 'relast'
 
-task fatJar(type: Jar) {
+tasks.register('fatJar', Jar) {
     dependsOn jar
     group = "build"
     archiveBaseName = 'relast'
@@ -179,7 +180,7 @@ publishing {
     }
 }
 
-task firstRelationsRun(type: RelastTest) {
+tasks.register('firstRelationsRun', RelastTest) {
     relast {
         inputFiles = [file('src/test/jastadd/relations/Relations.relast')]
         grammarName = 'src/test/jastadd/relations/Relations'
@@ -193,7 +194,10 @@ task firstRelationsRun(type: RelastTest) {
     }
 }
 
-task secondRelationsRun(type: RelastTest, dependsOn: firstRelationsRun) {
+tasks.register('secondRelationsRun', RelastTest) {
+    dependsOn firstRelationsRun
+    dependsOn compileJava
+    dependsOn processResources
     relast {
         inputFiles = [file('src/test/jastadd/relations/Relations.ast')]
         grammarName = 'src/test/jastadd/relations/Relations2'
@@ -211,7 +215,8 @@ task secondRelationsRun(type: RelastTest, dependsOn: firstRelationsRun) {
     }
 }
 
-task compileConstructorTest(type: RelastTest) {
+tasks.register('compileConstructorTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/constructors/Constructors.relast')]
         grammarName = 'src/test/jastadd/constructors/Constructors'
@@ -223,7 +228,8 @@ task compileConstructorTest(type: RelastTest) {
     }
 }
 
-task compileDefaultNamesTest(type: RelastTest) {
+tasks.register('compileDefaultNamesTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/relations/Relations.relast')]
         grammarName = 'src/test/jastadd/relations/Relations3'
@@ -237,7 +243,8 @@ task compileDefaultNamesTest(type: RelastTest) {
     }
 }
 
-task compileDefaultNamesResolverTest(type: RelastTest) {
+tasks.register('compileDefaultNamesResolverTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/resolver/Resolver.relast')]
         grammarName = 'src/test/jastadd/resolver/Resolver2'
@@ -251,7 +258,8 @@ task compileDefaultNamesResolverTest(type: RelastTest) {
     }
 }
 
-task compileLowerBoundsTest(type: RelastTest) {
+tasks.register('compileLowerBoundsTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/lowerbounds/LowerBounds.relast')]
         grammarName = 'src/test/jastadd/lowerbounds/LowerBounds'
@@ -264,7 +272,8 @@ task compileLowerBoundsTest(type: RelastTest) {
     }
 }
 
-task compileMultipleTest(type: RelastTest) {
+tasks.register('compileMultipleTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/multiple/Part1.relast'),
                       file('src/test/jastadd/multiple/Part2.relast'),
@@ -279,7 +288,8 @@ task compileMultipleTest(type: RelastTest) {
     }
 }
 
-task compileMultipleMixedTest(type: RelastTest) {
+tasks.register('compileMultipleMixedTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/multiple-mixed/Part1.relast'),
                       file('src/test/jastadd/multiple-mixed/Part2.relast'),
@@ -294,7 +304,8 @@ task compileMultipleMixedTest(type: RelastTest) {
     }
 }
 
-task compileResolverTest(type: RelastTest) {
+tasks.register('compileResolverTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/resolver/Resolver.relast')]
         grammarName = 'src/test/jastadd/resolver/Resolver'
@@ -308,7 +319,8 @@ task compileResolverTest(type: RelastTest) {
     }
 }
 
-task compileResolver2Test(type: RelastTest) {
+tasks.register('compileResolver2Test', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/resolver2/Resolver.relast')]
         grammarName = 'src/test/jastadd/resolver2/Resolver'
@@ -322,7 +334,8 @@ task compileResolver2Test(type: RelastTest) {
     }
 }
 
-task compileListNamesTest(type: RelastTest) {
+tasks.register('compileListNamesTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/listnames/ListNames.relast')]
         grammarName = 'src/test/jastadd/listnames/ListNames'
@@ -337,7 +350,8 @@ task compileListNamesTest(type: RelastTest) {
     }
 }
 
-task compileSerializerTest(type: RelastTest) {
+tasks.register('compileSerializerTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/serializer/Serializer.relast')]
         grammarName = 'src/test/jastadd/serializer/Serializer'
@@ -351,7 +365,8 @@ task compileSerializerTest(type: RelastTest) {
     }
 }
 
-task compileSerializerDefaultNamesTest(type: RelastTest) {
+tasks.register('compileSerializerDefaultNamesTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/serializer-names/Serializer.relast')]
         grammarName = 'src/test/jastadd/serializer-names/Serializer'
@@ -365,7 +380,8 @@ task compileSerializerDefaultNamesTest(type: RelastTest) {
     }
 }
 
-task compileSerializerPointerTest(type: RelastTest) {
+tasks.register('compileSerializerPointerTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/serializer-pointer/Serializer.relast')]
         grammarName = 'src/test/jastadd/serializer-pointer/Serializer'
@@ -378,7 +394,8 @@ task compileSerializerPointerTest(type: RelastTest) {
     }
 }
 
-task compileSerializerManualTest(type: RelastTest) {
+tasks.register('compileSerializerManualTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/serializer-manual/Serializer.relast')]
         grammarName = 'src/test/jastadd/serializer-manual/Serializer'
@@ -392,7 +409,8 @@ task compileSerializerManualTest(type: RelastTest) {
     }
 }
 
-task compileSerializerManualRelativeTest(type: RelastTest) {
+tasks.register('compileSerializerManualRelativeTest', RelastTest) {
+    dependsOn secondRelationsRun
     relast {
         inputFiles = [file('src/test/jastadd/serializer-manual-relative/Serializer.relast')]
         grammarName = 'src/test/jastadd/serializer-manual-relative/Serializer'
@@ -406,7 +424,7 @@ task compileSerializerManualRelativeTest(type: RelastTest) {
     }
 }
 
-task cleanTestGen(type: Delete) {
+tasks.register('cleanTestGen', Delete) {
     group 'verification'
     description 'Cleans all generated test resources'
 
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index e708b1c023ec8b20f512888fe07c5bd3ff77bb8f..41d9927a4d4fb3f96a785543079b8df6723c946b 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 41dfb87909a877d96c3af4adccce4c7a301b55a2..81aa1c0448a219c604f9ecd164af437de0fed21a 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index 4f906e0c811fc9e230eb44819f509cd0627f2600..1b6c787337ffb79f0e3cf8b1e9f00f680a959de1 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
-#!/usr/bin/env sh
+#!/bin/sh
 
 #
-# Copyright 2015 the original author or authors.
+# Copyright © 2015-2021 the original authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,67 +17,101 @@
 #
 
 ##############################################################################
-##
-##  Gradle start up script for UN*X
-##
+#
+#   Gradle start up script for POSIX generated by Gradle.
+#
+#   Important for running:
+#
+#   (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+#       noncompliant, but you have some other compliant shell such as ksh or
+#       bash, then to run this script, type that shell name before the whole
+#       command line, like:
+#
+#           ksh Gradle
+#
+#       Busybox and similar reduced shells will NOT work, because this script
+#       requires all of these POSIX shell features:
+#         * functions;
+#         * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+#           «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+#         * compound commands having a testable exit status, especially «case»;
+#         * various built-in commands including «command», «set», and «ulimit».
+#
+#   Important for patching:
+#
+#   (2) This script targets any POSIX shell, so it avoids extensions provided
+#       by Bash, Ksh, etc; in particular arrays are avoided.
+#
+#       The "traditional" practice of packing multiple parameters into a
+#       space-separated string is a well documented source of bugs and security
+#       problems, so this is (mostly) avoided, by progressively accumulating
+#       options in "$@", and eventually passing that to Java.
+#
+#       Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+#       and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+#       see the in-line comments for details.
+#
+#       There are tweaks for specific operating systems such as AIX, CygWin,
+#       Darwin, MinGW, and NonStop.
+#
+#   (3) This script is generated from the Groovy template
+#       https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+#       within the Gradle project.
+#
+#       You can find Gradle at https://github.com/gradle/gradle/.
+#
 ##############################################################################
 
 # Attempt to set APP_HOME
+
 # Resolve links: $0 may be a link
-PRG="$0"
-# Need this for relative symlinks.
-while [ -h "$PRG" ] ; do
-    ls=`ls -ld "$PRG"`
-    link=`expr "$ls" : '.*-> \(.*\)$'`
-    if expr "$link" : '/.*' > /dev/null; then
-        PRG="$link"
-    else
-        PRG=`dirname "$PRG"`"/$link"
-    fi
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+    APP_HOME=${app_path%"${app_path##*/}"}  # leaves a trailing /; empty if no leading path
+    [ -h "$app_path" ]
+do
+    ls=$( ls -ld "$app_path" )
+    link=${ls#*' -> '}
+    case $link in             #(
+      /*)   app_path=$link ;; #(
+      *)    app_path=$APP_HOME$link ;;
+    esac
 done
-SAVED="`pwd`"
-cd "`dirname \"$PRG\"`/" >/dev/null
-APP_HOME="`pwd -P`"
-cd "$SAVED" >/dev/null
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
 
 APP_NAME="Gradle"
-APP_BASE_NAME=`basename "$0"`
+APP_BASE_NAME=${0##*/}
 
 # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
 DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
 
 # Use the maximum available, or set MAX_FD != -1 to use that value.
-MAX_FD="maximum"
+MAX_FD=maximum
 
 warn () {
     echo "$*"
-}
+} >&2
 
 die () {
     echo
     echo "$*"
     echo
     exit 1
-}
+} >&2
 
 # OS specific support (must be 'true' or 'false').
 cygwin=false
 msys=false
 darwin=false
 nonstop=false
-case "`uname`" in
-  CYGWIN* )
-    cygwin=true
-    ;;
-  Darwin* )
-    darwin=true
-    ;;
-  MINGW* )
-    msys=true
-    ;;
-  NONSTOP* )
-    nonstop=true
-    ;;
+case "$( uname )" in                #(
+  CYGWIN* )         cygwin=true  ;; #(
+  Darwin* )         darwin=true  ;; #(
+  MSYS* | MINGW* )  msys=true    ;; #(
+  NONSTOP* )        nonstop=true ;;
 esac
 
 CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
@@ -87,9 +121,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
 if [ -n "$JAVA_HOME" ] ; then
     if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
         # IBM's JDK on AIX uses strange locations for the executables
-        JAVACMD="$JAVA_HOME/jre/sh/java"
+        JAVACMD=$JAVA_HOME/jre/sh/java
     else
-        JAVACMD="$JAVA_HOME/bin/java"
+        JAVACMD=$JAVA_HOME/bin/java
     fi
     if [ ! -x "$JAVACMD" ] ; then
         die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@@ -98,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
 location of your Java installation."
     fi
 else
-    JAVACMD="java"
+    JAVACMD=java
     which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
 
 Please set the JAVA_HOME variable in your environment to match the
@@ -106,80 +140,95 @@ location of your Java installation."
 fi
 
 # Increase the maximum file descriptors if we can.
-if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
-    MAX_FD_LIMIT=`ulimit -H -n`
-    if [ $? -eq 0 ] ; then
-        if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
-            MAX_FD="$MAX_FD_LIMIT"
-        fi
-        ulimit -n $MAX_FD
-        if [ $? -ne 0 ] ; then
-            warn "Could not set maximum file descriptor limit: $MAX_FD"
-        fi
-    else
-        warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
-    fi
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+    case $MAX_FD in #(
+      max*)
+        MAX_FD=$( ulimit -H -n ) ||
+            warn "Could not query maximum file descriptor limit"
+    esac
+    case $MAX_FD in  #(
+      '' | soft) :;; #(
+      *)
+        ulimit -n "$MAX_FD" ||
+            warn "Could not set maximum file descriptor limit to $MAX_FD"
+    esac
 fi
 
-# For Darwin, add options to specify how the application appears in the dock
-if $darwin; then
-    GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
-fi
+# Collect all arguments for the java command, stacking in reverse order:
+#   * args from the command line
+#   * the main class name
+#   * -classpath
+#   * -D...appname settings
+#   * --module-path (only if needed)
+#   * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
 
 # For Cygwin or MSYS, switch paths to Windows format before running java
-if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
-    APP_HOME=`cygpath --path --mixed "$APP_HOME"`
-    CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
-
-    JAVACMD=`cygpath --unix "$JAVACMD"`
-
-    # We build the pattern for arguments to be converted via cygpath
-    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
-    SEP=""
-    for dir in $ROOTDIRSRAW ; do
-        ROOTDIRS="$ROOTDIRS$SEP$dir"
-        SEP="|"
-    done
-    OURCYGPATTERN="(^($ROOTDIRS))"
-    # Add a user-defined pattern to the cygpath arguments
-    if [ "$GRADLE_CYGPATTERN" != "" ] ; then
-        OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
-    fi
+if "$cygwin" || "$msys" ; then
+    APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+    CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+    JAVACMD=$( cygpath --unix "$JAVACMD" )
+
     # Now convert the arguments - kludge to limit ourselves to /bin/sh
-    i=0
-    for arg in "$@" ; do
-        CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
-        CHECK2=`echo "$arg"|egrep -c "^-"`                                 ### Determine if an option
-
-        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition
-            eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
-        else
-            eval `echo args$i`="\"$arg\""
+    for arg do
+        if
+            case $arg in                                #(
+              -*)   false ;;                            # don't mess with options #(
+              /?*)  t=${arg#/} t=/${t%%/*}              # looks like a POSIX filepath
+                    [ -e "$t" ] ;;                      #(
+              *)    false ;;
+            esac
+        then
+            arg=$( cygpath --path --ignore --mixed "$arg" )
         fi
-        i=`expr $i + 1`
+        # Roll the args list around exactly as many times as the number of
+        # args, so each arg winds up back in the position where it started, but
+        # possibly modified.
+        #
+        # NB: a `for` loop captures its iteration list before it begins, so
+        # changing the positional parameters here affects neither the number of
+        # iterations, nor the values presented in `arg`.
+        shift                   # remove old arg
+        set -- "$@" "$arg"      # push replacement arg
     done
-    case $i in
-        0) set -- ;;
-        1) set -- "$args0" ;;
-        2) set -- "$args0" "$args1" ;;
-        3) set -- "$args0" "$args1" "$args2" ;;
-        4) set -- "$args0" "$args1" "$args2" "$args3" ;;
-        5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
-        6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
-        7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
-        8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
-        9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
-    esac
 fi
 
-# Escape application args
-save () {
-    for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
-    echo " "
-}
-APP_ARGS=`save "$@"`
+# Collect all arguments for the java command;
+#   * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+#     shell script including quotes and variable substitutions, so put them in
+#     double quotes to make sure that they get re-expanded; and
+#   * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+        "-Dorg.gradle.appname=$APP_BASE_NAME" \
+        -classpath "$CLASSPATH" \
+        org.gradle.wrapper.GradleWrapperMain \
+        "$@"
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+#   readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+#   set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
 
-# Collect all arguments for the java command, following the shell quoting and substitution rules
-eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+eval "set -- $(
+        printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+        xargs -n1 |
+        sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+        tr '\n' ' '
+    )" '"$@"'
 
 exec "$JAVACMD" "$@"