Building IBM z/OS Connect APIs with Gradle
The zosConnect-3.0 feature uses Gradle to build API provider and API requester WAR files.
zosConnect-3.0 Applies to zosConnect-3.0.
What is a Gradle?
Gradle is an open source build automation tool that is flexible enough to build almost any type of software. A version of Gradle is shipped as part of the z/OS Connect installation in <installation_path>/gradle.zip. If Gradle is not installed already, you can expand this file and use the Gradle within it to build API projects.
For more information about Gradle, see
What is Gradle?
How Gradle is used in the zosConnect-3.0 feature
z/OS Connect uses Gradle to package an API project into a WAR file.
- com.ibm.zosconnect.gradle for API provider. For reference see,
IBM z/OS Connect API provider Gradle Plugin.
- com.ibm.zosconnect.requester for API requester. For reference, see
IBM z/OS Connect API requester Gradle Plugin.
When you build an API project, the Gradle
dependencies are downloaded by Gradle as part of the
build to a local Gradle dependency cache on the
build machine. For more information, see
Gradle Dependency Cache. If you are working in an offline
(airgapped) environment, see Using Gradle in an offline (airgapped) environment.
These Gradle dependencies are defined in the
build.gradle file and the settings.gradle file in the
repositories section where you can also configure whether to use a public or
private repository. For more information, see
Declaring Repositories.
z/OS Connect Designer uses the API provider Gradle plug-in (com.ibm.zosconnect.gradle) to package an API project into a WAR file. As you develop your API project in the z/OS Connect Designer, the Gradle build runs in the background so the API project is available to test.
Installing Gradle
Install a supported release of Gradle on the
system that you are going to develop or package a z/OS Connect API on. For more information, see IBM z/OS Connect system requirements and
Installing Gradle. Alternatively, the z/OS Connect installation includes the
gradle.zip file. Expand this file on the system where the API is being built
and packaged.
The z/OS Connect Designer image contains an expanded
version of Gradle which is ready to use in the
/opt/gradle/bin directory. This directory has been added to the PATH in the z/OS Connect Designer (ibm-zcon-designer)
image.
Using Gradle to build the API project
- A z/OS Connect project is available. Ideally, the API project source is checked into a Source Code Management (SCM) repository.
- Gradle 7.6.1 or higher is installed on the machine running the builds. For more information about supported Gradle versions, see IBM z/OS Connect system requirements.
- For API provider projects, the z/OS Connect
API provider
Gradle plug-in,
com.ibm.zosconnect.gradlethat is automatically downloaded in an online environment, must be available to build the API provider projectWARfiles. For more information, seemaven central repository - com.ibm.zosconnect.provider
- For API requester projects, the z/OS Connect
API requester
Gradle plug-in,
com.ibm.zosconnect.requesterthat is automatically downloaded in an online environment, is available to build the API requester projectWARfiles. For more information, seemaven central repository - com.ibm.zosconnect.requester.
- Choose one of the following options for the directory where the API project
WAR files are deployed.
- The drop-ins directory
- The drop-ins directory, /config/dropins is a special directory that is supported by WebSphere® Application Server Liberty. It allows WAR files to be deployed and dynamically loaded into the running z/OS Connect Server with no additional definitions that are required in the configuration file.
- A directory other than drop-ins
- This is required in any of the following situations:
- The APIs OpenAPI definition
servers:section contains an entry for the context root value of the API, which is not just /.Note: The API project WAR file is generated with a context root of /. - Multiple APIs are to be deployed to the same z/OS Connect Server. Because the API project
WAR file is generated with a context root of /, and
multiple API WAR files in the same server must have unique context root values,
you need to include a unique context root value (not /) in the APIs OpenAPI definition
servers:section. For example, to use a context root of /EmployeesApi.openapi: 3.0.0 ... servers: url: https://localhost:9443/EmployeesApi ...
These API project WAR files are typically deployed into the /config/apps directory. You must create this directory but you can choose a different name.
You also need to configure awebApplicationelement in theserver.xmlconfiguration file. For example,<webApplication location="/config/apps/EmployeesApi.war" name="EmployeesApi" contextRoot="/EmployeesApi"/>Where:locationis the fully qualified path to the deployed API WAR file.nameis an optional attribute that is used in log messages to identify the API.contextRootvalue must match the context root value that is specified in theservers:entry of the OpenAPI definitionservers:section.
- The APIs OpenAPI definition
When the prerequisites are complete, use the following steps to build the z/OS Connect API project by using Gradle.
- Extract the z/OS Connect API project from your Source Code Management (SCM) solution.
- Start the Gradle build process. Use the gradle build command to run a build
task that packages the API project as a Web Application archive (
WAR) file. When defining this task in your DevOps pipeline you can use thebuild.gradle, andsettings.gradlefile found in the API project. For more information about the Gradle plug-ins and their requirements, see Using the API provider Gradle plug-in and Using the API requester Gradle plug-in.Note: Started taskEach API requester project
WARfile must have a unique name. For more information about theapiNameproperty in the API requester Gradle plug-in properties and options, see The API requester Gradle plug-in properties and options.Important:For multiple API project WAR files to function when deployed to a single z/OS Connect Server, you must ensure that your OpenAPI specification includes acontextRootdefined within theserverssection. ThecontextRootattribute specifies the entry point of the deployed application. For example, to use acontextRootof/myContextRootin the APIs OpenAPI definition servers section:
This definition must match theopenapi: 3.0.0 ... servers: url: "https://localhost:9443/myContextRoot" ...contextRootattribute value of thewebApplicationelement in yourserver.xmlfile. An example of the configuration might be:<webApplication location="${server.config.dir}/apps/api.war" name="EmployeesApi" contextRoot="/myContextRoot"/>If the server entry in the server section of the OpenAPI definition includes a
contextRootvalue, then this value must be specified in thecontextRootattribute of the correspondingwebApplicationelement, even when only a single API is deployed to the z/OS Connect Server.Each API deployed to the same z/OS Connect Server requires a uniquecontextRoot. For example to deploy two APIs namedsample-db2-apiandsample-ims-api:<webApplication location="${server.config.dir}/apps/sample-db2-api.war" name="sample-db2-api" contextRoot="/sampleDb2Api"/><webApplication location="${server.config.dir}/apps/sample-ims-api.war" name="sample-ims-api" contextRoot="/sampleImsApi"/> - Identify the appropriate configuration for the environment for which the image is built. For example, your API project might require different property substitutions that relate to the z/OS Connect Designer environment variables, such as CICS_USER, DB2_USER, CICS_PASSWORD, CICS_HOST and CICS_PORT or extra security configuration is needed.
Using Gradle in an offline (airgapped) environment
If you build an API project in an offline (airgapped) environment, the required Gradle dependencies are available in the <installation_path>/dependencies.zip file as part of z/OS Connect. Expand this file on the build machine and use instead of a remote repository.
When the dependencies.zip file is expanded into
<dir>/gradleLibs, the location of the repository must be specified in the
settings.gradle file for the API project. For example,
pluginManagement {
repositories {
maven {
url '<dir>/gradleLibs'
}
}
}
Containers The z/OS Connect Designer image contains an expanded Gradle dependencies.zip file that is ready to use in the /templates/gradeLibs directory.
Using Gradle on z/OS
POSIX1.2001 must be used. The default shell /bin/sh on z/OS
cannot be used to run Gradle. Modern shell environments are available on z/OS 3.1 or later and
through the no-cost IBM Open Enterprise Foundation for z/OS suite of tools for z/OS 2.5 or
later.To run the Gradle script under a different shell, prefix the Gradle command with the shell name. For example: bash ./gradle build
It is necessary to set environment variables to help ensure Gradle runs correctly on z/OS.
- Set the following environment variables before starting Gradle.
LANG=en_US.UTF-8GRADLE_OPTS="-Dfile.encoding=UTF-8"_BPXK_AUTOCVT=ON - If using the
Gradle Wrapper, then ensure the gradlew file in the root of the project is tagged as ASCII.
chtag -tc ISO8859-1 ./gradlew - If using an installation of Gradle, then ensure
that the Gradle shell script is tagged as ASCII. For
example, extract the installation with the correct environment variables to have the tagging
automatically
applied:
_CEE_RUNOPTS="FILETAG(AUTOCVT,AUTOTAG)" unzip gradle-X.Y-bin.zipAlternatively, if
unzipis unavailable, you can usejarto extract the installation and then manually tag the script and set it executable.jar -xvf ../gradle-X.Y-bin.zip chtag -tc ISO8859-1 <Gradle installation>/bin/gradle chmod +x <Gradle installation>/bin/gradle