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

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.

Method 1:

Add the following block to the top of your build.gradle:

plugins {
id "com.bmuschko.cargo" version "2.3"}

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 build.gradle:

cargo {// Configures which commands require a built artifact
cargoRunLocal.dependsOn war
cargoStartLocal.dependsOn war
cargoDeployRemote.dependsOn war
cargoRedeployRemote.dependsOn war
cargoRedeployLocal.dependsOn war
containerId ='glassfish5x'// Define deploy artifact properties
deployable {
context ="/"}// Only necessary for local commands
local {
homeDir = file(payaraHome)}// Only necessary for remote commands
remote {
hostname ="localhost"
username ="admin"
password =""
containerProperties {// this is necessary only to pass blank password correctly to the cargo deployer because of a bug in the cargo gradle plugin
property 'cargo.remote.password', payaraPassword
}}}

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.