There is a lot of content detailing the use of Maven and Payara Server together (see our blog and documentation) but with Gradle still gaining popularity: this blog will show you how to use it to deploy to Payara Server.
This blog will assume you already have a Gradle project setup, but in case you don't, a sample Gradle project can be found here. The sample contains the Gradle wrapper, so if you don't have Gradle installed you can replace all calls to the
gradle command with the ./
gradlew wrapper program (or ./
gradlew.bat for windows) found in the project root. If you'd rather install Gradle, you can do so by following the guide on Gradle's website.
Deploying the Project
There are two methods for deploying to Payara Server using Gradle:
- Implement Cargo, a tool for deploying web applications to application servers
- Write several Gradle tasks yourself (for Maven users they're similar to Ant scripts tied to maven goals) to achieve the same goals
The first method is more flexible, as it can redirect the server output, deploy to remote instances and change debugging ports etc. The second method is more fun and will also run faster. The local commands for the first method and the domain commands for the second methods will require a local Payara Server installation.
Add the following block to the top of your build.gradle:
This code block will download the external Cargo Gradle dependency and apply it to the project.
Add the following blocks to the relevant place in your build file. (For most projects this will be very near the top).
If you already have dependencies, add the ones shown above to your current list.
Add the following block to the bottom of your
Replace the value of 'context' with the context path that you want the project deployed to. Use '/' to deploy it to the root of the server (at
localhost:8080). The commands that are configured at the top of the block won't require a
gradle build before using them, since they depend on it automatically.
The following commands can be used to manage your application with regard to Payara Server:
While the server is running, you can make changes to your project and then redeploy your app to see the changes without needing a server restart. To see the full plugin documentation, refer to this guide.
Insert the following code at the bottom of your build.gradle:
You can now start and stop a local Payara Server instance, and redeploy your app with:
You can rename any of the tasks as you see fit.
You've now successfully setup Gradle to deploy your web app to Payara Server!