Home > database >  Is it possible to run Gradle on z/OS?
Is it possible to run Gradle on z/OS?

Time:01-02

I'm attempting to run Gradle on z/OS, but running into issues.

I have downloaded Gradle to z/OS, and then unzipped it.

When I test out the installation by running the following:

./gradle-7.6/bin/gradle

I get the following:

./gradle-7.6/bin/gradle: line 1: syntax error near unexpected token `|'
./gradle-7.6/bin/gradle: line 1: <a whole lot of garbage follows after here>

How should I go about setting up Gradle such that it runs on z/OS as I'd expect it to run elsewhere?

CodePudding user response:

Gradle can run in Unix System Services (USS) on z/OS, but there are a few important configuration changes you'll have to make to deal with Gradle's expectation that the default encoding of the platform is UTF-8.

This problem can be divided into 2 parts. The first is to ensure that Gradle is correctly installed with its files tagged with the correct coded character set (which is your current problem). The second is to ensure the environment is set up to run Gradle.

Installing Gradle on z/OS

Note that Gradle can be used in 2 different ways:

  • The first is via a Gradle installation, which you can point to directly or add to your $PATH, and then you run like this:

    gradle <tasks>
    
  • The second is via the Gradle Wrapper, which is a couple of scripts, a JAR and a properties file that you add to your project and which will ensure that the exact same version of Gradle is used whomever runs that build, by running like this:

    ./gradlew <tasks>
    

For each of these methods, you'll need to run some z/OS specific setup:

Setting up a Gradle installation

Gradle comes as a zip file. The best way to extract this is to use the unzip command, if available. When doing so, set the _CEE_RUNOPTS environment variable to automatically tag files with the correct coded character set, as so:

_CEE_RUNOPTS="FILETAG(AUTOCVT,AUTOTAG)" unzip gradle-X.Y-bin.zip 

Alternatively, if you don't have unzip available but you do have Java (which you will need in order to run Gradle!) then you can use the jar utility from the Java installation. This utility won't correctly tag files, nor will it set Gradle to be executable, so you will need to do something like this:

jar -xvf /path/to/gradle-X.Y-bin.zip
chtag -tc ISO8859-1 ./bin/gradle
chmod  x ./bin/gradle

Either way, you can check that the installation looks as you would expect by listing the files, their permissions and their tags:

                    drwxr-xr-x   2 MYUSER   TSOUSER     8192 Feb  1  1980 .
                    drwxr-xr-x   5 MYUSER   TSOUSER     8192 Feb  1  1980 ..
m ISO8859-1   T=off -rwxr-xr-x   1 MYUSER   TSOUSER     8487 Feb  1  1980 gradle
m ISO8859-1   T=off -rwxr-xr-x   1 MYUSER   TSOUSER     2858 Feb  1  1980 gradle.bat

Note that the gradle script is executable (x in the permissions) and tagged as ISO8859-1, i.e. ASCII.

Setting up a project that uses the Gradle Wrapper

When a project uses the Gradle Wrapper, then there is no central Gradle installation that needs setting up. Instead, there is a gradlew script in the root of the project that itself downloads Gradle to a central cache and runs it. We simply need to tag that file as ASCII to ensure it is read correctly:

chtag -tc ISO8859-1 ./gradlew

With the installation set up, we can now focus on running Gradle.

Running Gradle on z/OS

z/OS USS is typically going to be using some EBCDIC variant encoding both for files and for the console, and when the JVM on z/OS starts, the default setting for the system property file.encoding will honour that. We can override that by setting the system property. It's most convenient to do this using the GRADLE_OPTS environment variable in your .profile, as you'll need to apply this to all Gradle environments.

Additionally, because of Gradle's use of daemon processes, and expectation to be able to read their output in UTF-8, we'll have to change the output encoding of those processes to be UTF-8 with the LANG environment variable. You'll need to set this on a per-invocation basis, I don't believe there's a convenient way of doing that for all gradle invocations, and you certainly don't want to change it for everything.

And finally, the shell will need to be able to read the initial script, whether that be gradle in a Gradle installation or gradlew for the Gradle Wrapper in the root of a project. If we set the _BPXK_AUTOCVT environment variable to ON, then the shell will respect the file tagging. This is probably OK to set on in your .profile too.

So:

LANG=en_US.UTF-8 GRADLE_OPTS="-Dfile.encoding=UTF-8" _BPXK_AUTOCVT=ON /gradle-7.6/bin/gradle

Or in a project using the Gradle Wrapper:

LANG=en_US.UTF-8 GRADLE_OPTS="-Dfile.encoding=UTF-8" _BPXK_AUTOCVT=ON ./gradlew

Alternatively, if we set some of these variables in .profile:

# .profile contents:
GRADLE_OPTS="-Dfile.encoding=UTF-8"
_BPXK_AUTOCVT=ON

Then:

LANG=en_US.UTF-8 /gradle-7.6/bin/gradle

Or in a project using the Gradle Wrapper:

LANG=en_US.UTF-8 ./gradlew
  • Related