back to all blogsSee all blog posts

Cloud-native development of Gradle-built applications with the Open Liberty devfile stack

image of author
Edward Mezarina on Sep 14, 2021
Post available in languages:

The Open Liberty devfile stack now allows you build and deploy new and existing cloud-native applications using Gradle. The stack leverages Open Liberty Gradle Plugin capabilities to manage the Liberty server and Gradle-built applications.

In this post, we’ll use the Open Liberty devfile stack and Openshift odo to deploy an application that uses Gradle to a Kubernetes cluster.

Open Liberty devfile stack

The Open Liberty devfile stack provides much of the infrastructure (Open Liberty, Maven/Gradle, Open J9, etc.) needed to start developing applications that use Maven or Gradle, and it is made available as Maven and Gradle development images. The devfiles that are provided by the stack use these images as a base to build and run your applications.

The Open Liberty devfile stack provides two fully configured devfiles: A Maven based devfile and a Gradle based devfile. These devfiles define the environment and steps to build and deploy your application using the Open Liberty runtime.

OpenShift Do (odo)

Odo is a simple CLI tool to create devfile-based components that interact directly with your Kubernetes cluster. With odo you can set up the environment, and also build, deploy, access, and debug your application. Directives to manage the environment and application are provided by a component’s devfile.

Try it out

To begin, you need three things:

  • Kubernetes cluster (i.e. Openshift, Minikube). Be sure to log in. Odo will interact with your kubernetes cluster.

  • Openshift Do. If you have not already installed odo, do so now by following the instructions outlined in the odo documentation.

  • An application using Gradle. You can use your own application, or use one of the applications provided by the stack, such as the intro or starter application. For this blog, we will use the intro application. This is a basic application that uses JAX-RS and MicroProfile technologies. For instructions on how to use the starter application, see Using the Default Starter: Getting started.

First, clone the application.

git clone [email protected]:OpenLiberty/devfile-stack-intro.git && \
cd devfile-stack-intro

Create an odo component of type java-openliberty-gradle. When the component is created, the Gradle based devfile provided by the Open Liberty devfile stack is downloaded to the root of the application.

odo create java-openliberty-gradle my-ol-component

Deploy the application on your Kubernetes cluster.

odo push

That is all. The application is now deployed on your cluster and a URL is available to access it.

Notice that you did not have to create any Kubernetes resources to deploy the application. The work to make that happen was done behind the scenes by odo and the stack.

Now, let’s see if the application was deployed successfully. We can get the URL to access the application by running odo url list:

odo url list


Found the following URLs for component my-ol-component
NAME     STATE      URL                                                                     PORT     SECURE     KIND
ep1      Pushed           9080     false      route

The default endpoint name assigned by the stack’s devfile is ep1.

To access the REST endpoint for the application, append /api/resource to the URL listed in the previous step, for example, You can access this endpoint through a browser or by running a curl command:

curl -w "\n"


Hello! Welcome to Open Liberty

If you get back Hello! Welcome to Open Liberty as a response, the application is up and running.

Now, all that is left to do is to have odo watch for changes in the application.

odo watch

Odo will now push any application changes to the cluster automatically without the need for you to manually push (odo push) your source code updates to the cluster. All you need to do to see your updates is to refresh the browser or access the endpoint again.

Learn more