読者です 読者をやめる 読者になる 読者になる

mike-neckのブログ

JavaかJavaFXかJavaEE(なんかJava8が多め)

Payara-micro meets Gradle, Gradle Payara Plugin(unofficial) is available! #gradle #payara

f:id:mike_neck:20150906224045j:plain

meets

f:id:mike_neck:20150818084108g:plain

Gradle Payara plugin is available now!

Detail information is available at gradle plugin portal.

And the repository is here.

github.com

Install

Add following script to your build.gradle, you can use Gradle Payara plugin.

All Gradle version

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.org.mikeneck:payara-plugin:0.0.2"
  }
}

apply plugin: "org.mikeneck.payara-plugin"

New Plugin mechanism (introduced in Gradle2.1)

plugins {
  id "org.mikeneck.payara-plugin" version "0.0.2"
}

Features

Applying this plugin, the following tasks and plugins are applied to your project.

  • war plugin will be automatically applied to your project.
  • payaraRunWar task which assembles JavaEE app into war file and deploy it to payara-micro server.
  • payaraStop tasks which stops payara-micro server ran by payaraRunWar.

How to configure

You can configure payara-micro server, with payara{} block.

payara {
  httpPort 8000 // default 8080
  stopPort 3000 // default 5050
  stopCommand = 'STOP-PAYARA' // default 'stop'
  daemon true // default false
}

Available attributes are

attributes type description
httpPort int port number whom payara-micro use as http-listener.
stopPort int port number for user to stop payara-micro server.
stopCommand String command string for user to stop payara-micro server.
daemon boolean If true payara-micro server runs in backend, and gradle task will finish in success. If false payara-micro server blocks gradle tasks execution.

But currently daemon mode is not implemented, so this feature is not available.

Running task

Running payara-micro server

To start payara-micro server and deploy war file created by your project...

$ gradle --daemon payaraRunWar

With this command and configuration described before, you can access Java EE application via http://localhost:8000/war-archive-name.

Stopping payara-micro server

To stop payara-micro server, there are two way to stop it.

via http access

With the configuration above...

$ curl -X POST -d 'STOP-PAYARA' http://localhost:3000/
via payaraStop task

or payaraStop task can stop payara-micro server.

$ gradle --daemon payaraStop

Limittage

There are some limitation.

  • The configuration daemon has no effect on these tasks.
  • Multiple wars cannot be deployed.
  • Multiple payara-micro instances with hazelcast are not available.
  • Redeployment of war file(like jetty plugin) is not available.
  • Deploying none war file(i.e. deploying project classes like jettyRun task) is not available.
  • Customized glassfish-config file cannot be installed.
    • Thus customized data-source is not available.
    • Thus derby is default RDBMS.

I'm now implementing daemon mode in the next version (0.0.3).

Bugs

There are a lot of exception stack traces. I'm not good at Payara's implementation and Glassfish's implementation, but I'll fix them one by one. I'll appreciate it if you would send Pull Request to my repository.

Motivation

There was an requesting issue to provide Gradle payara plugin in Feb 2015. But it seems nobody is trying to create the plugin, so I decided to create it.

github.com

This and That

For the first time payara-micro cannot be started in Gradle task execution context, so unexpectedly I created an pull request to payara micro.

github.com

And Payara team merged it soon.

I respect Payara team's quick work.