Andrey Hihlovskiy

Professional blog on groovy, gradle, Java, Javascript and other stuff.

Category Archives: groovy

Powerful feature in Gretty 0.0.24 – full support of Spring Boot 1.1.0

Today is a wonderful day: Spring Boot 1.1.0 was released and I released Gretty version 0.0.24.

Gretty is a feature-rich gradle plugin for running web-apps on Jetty. It supports multiple Jetty versions (7, 8 and 9), multiple web-apps and many more. It wraps Jetty functions as convenient Gradle tasks and configuration DSL. A complete list of Gretty features is available in feature overview.

There is new powerful feature in Gretty 0.0.24: it supports running Spring Boot web-apps out-of-the-box. All Gretty features, including (but not limited to) debugging, code coverage and integration tests, also apply to spring-boot web-apps.

Simplest Gretty setup with Spring Boot:


buildscript {
ext {
springBootVersion = '1.1.0.RELEASE'
}
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-loader-tools:${springBootVersion}"
classpath "org.springframework.boot:spring-boot-dependency-tools:${springBootVersion}"
classpath 'org.akhikhl.gretty:gretty-spring-boot-plugin:0.0.24'
}
}
apply plugin: 'java'
apply plugin: 'gretty-spring-boot'

view raw

build.gradle

hosted with ❤ by GitHub

You get Gretty as maven artifacts at jcenter and maven central under the group “org.akhikhl.gretty”.

Full Gretty sources and examples are available at https://github.com/akhikhl/gretty

Full Gretty documentation is available at http://akhikhl.github.io/gretty-doc/

 

Killer feature in Gretty version 0.0.18 – multiple web-apps support

Let’s assume, you are developing web-applications with JVM-based languages and technologies and are looking for the solution of the following problem:

You have a bunch of web-apps, that must run all at the same time, because they call each other. You also want to debug multiple web-apps and even run integration tests – on the complete bunch.

Here is the solution to this problem: use Gretty. This is gradle plugin, capable of exactly this: running multiple web-apps, debugging, integration tests. Of course, it is open-source and available at jcenter and maven central.

Gretty can start arbitrary number of web-apps of various types: gradle projects, WAR-files in the file system and even WAR-files from maven dependencies.
Multiple web-apps feature works out-of-the-box in configureless mode, although it is fully configurable/customizable.

The central concept of Multiple web-apps feature is farm – a collection of web-apps, that should run together.

There are two ways to define and use farms:

  • Default farm is automatically created for you by Gretty. You may add artbitrary web-apps to it and then invoke farm-specific tasks: farmRun, farmRunDebug, etc. Note that farm-specific tasks are not using gretty tasks (jettyRun, jettyRunDebug, etc.), but they understand and use gretty configurations.
  • Named farms, which you create yourself in gradle script. You can add as many named farms as you want, and you can add web-apps to farms in arbitrary constellations. Each named farm provides a specific set of farm tasks. For example, if you define farm with name “XYZ”, there will be new tasks farmRunXYZ, farmRunDebugXYZ, etc. available.

You can start using multiple web-apps support right away, using the following scenario as a starting point:

Create three empty folders: ProjectA, ProjectB and ProjectC, so that folder tree looks like this:

ProjectA
|-- ProjectB
\-- ProjectC

Create file “ProjectA/settings.gradle”, insert code:

include 'ProjectA', 'ProjectB'

Explanation: we organize multi-project setup, so that multiple web-apps can be started/stopped by gretty-farm plugin.

Create file “ProjectA/build.gradle”, insert code:

buildscript {
  repositories {
    jcenter()
  }

  dependencies {
    classpath 'org.akhikhl.gretty:gretty-plugin:+'
  }
}

apply plugin: 'gretty-farm'

Create file “ProjectA/ProjectB/build.gradle”, insert code:

apply plugin: 'gretty'

Create file “ProjectA/ProjectC/build.gradle”, insert code:

apply plugin: 'gretty'

Done! Now you can run multiple web-apps by running the following command in ProjectA:

gradle farmRun

Expected output:

Jetty server 9.1.0.v20131115 started.
:ProjectB runs at the address http://localhost:8080/ProjectB
:ProjectC runs at the address http://localhost:8080/ProjectC
servicePort: 9900, statusPort: 9901
Press any key to stop the jetty server.

Of course, you’ll get 404 in the browser, because web-apps don’t contain any pages. But, as soon as you add pages or/and servlets to the web-apps, things will get real.

By default farm automatically adds all subprojects of the farm project, which are facilitated with gretty plugin, to web-apps list. You can also explicitly add web-apps to the given farm.

Gretty-farm plugin defines new, distinct set of tasks for running farms: farmRun, farmRunDebug, farmRunWar, farmRunWarDebug, etc.

Gretty version 0.0.15 is out!

I release Gretty (gradle plugin for jetty) version 0.0.15!

New: fast-reload of webapp-resources, jdk8-compatibility.

Sources and documentation at https://github.com/akhikhl/gretty.

Also available on jcenter & maven central!
gretty_logo

Gretty 0.0.14 is out!

Hello there,

Gretty version 0.0.14 is out – on github, on maven central and jcenter!

What’s new: now Gretty supports jvmArgs parameter in plugin extension. See more information in what’s new section of the documentation.

Gretty is a feature-rich Gradle plugin, designed for running Web-Applications on Jetty. See more information in main features section of the documentation.

Many thanks to Justin Munn for contribution!

Gretty version 0.0.13 is out!

Gretty is a feature-rich gradle plugin for running web-applications under jetty.

New in version 0.0.13:

  • support of META-INF/web-fragment.xml and META-INF/resources
  • integration tests for most of the examples
  • integration of the build scripts with bintray and availability of the new version on jcenter

Full sources, documentation and examples: https://github.com/akhikhl/gretty

Gretty 0.0.13 artifacts are available both on maven central and on jcenter under the group “org.akhikhl.gretty”.

Gretty version 0.0.11 is out!

Gretty is a feature-rich gradle plugin for running web-applications under jetty.

New in version 0.0.11: now it’s possible to specify logback configuration file (.groovy or .xml) via plugin extension property “logbackConfigFile”.

Full sources, documentation and examples: https://github.com/akhikhl/gretty

Gretty 0.0.11 is also available on maven central under group “org.akhikhl.gretty”.

GVM – tool for managing groovy/gradle versions

Just discovered GVM – Groovy enVironment Manager ( http://gvmtool.net/ )
First impression: it’s like apt-get, but for groovy-based frameworks. Second impression: support of multiple versions is very useful thing.
Will use it at home and in office to automate installation of groovy-related stuff.

Gretty Plugin is now on Maven Central

I published Gretty Plugin to maven central, coordinates: org.akhikhl.gretty:gretty-plugin:0.0.4.
Project home: https://github.com/akhikhl/gretty
scm: https://github.com/akhikhl/gretty.git, git@github.com:akhikhl/gretty.git

Gretty Plugin is actually gradle plugin for running web-applications under jetty 8.1.8 and servlet API 3.0.1.

groovy script for running jetty server

The following script starts jetty server and opens the folder, specified on command line, for http access (read-only):

#!/usr/bin/env groovy

@Grab('javax.servlet:javax.servlet-api:3.0.1')
@Grab(group='org.eclipse.jetty', module='jetty-webapp', version='8.1.8.v20121106')
@Grab(group='org.eclipse.jetty', module='jetty-server', version='8.1.8.v20121106', transitive=false)
@Grab(group='org.eclipse.jetty', module='jetty-servlet', version='8.1.8.v20121106', transitive=false)
@GrabExclude('org.eclipse.jetty.orbit:javax.servlet')

import org.eclipse.jetty.server.Server
import org.eclipse.jetty.servlet.*
import groovy.servlet.*

def publishedFolder = args ? args[0] : '.'

def server = new Server(8080)
def context = new ServletContextHandler(server, '/', ServletContextHandler.SESSIONS)
def webappContext = new org.eclipse.jetty.webapp.WebAppContext(publishedFolder, '/jetty')
context.setHandler(webappContext)
server.start()
println 'Jetty server started. Press Ctrl+C to stop.'

Usage:

  1. Save this script to file “jetty.groovy”
  2. Invoke on command-line:
    groovy jetty.groovy /path/to/some/folder"
  3. Enter address in web-browser:
    http://localhost:8080/jetty

Expected result: you see the content of the folder “/path/to/some/folder” in the web-browser.

groovy switch: nasty bug

I found nasty error in Groovy compiler. Consider the following code:

byte b = 1
switch(b) {
  case 0..9:
    println 'it is between 0 and 9'
    break
  default:
    println 'it is something else'
}

It executes ‘default’ part, not the part with 0..9, which is not what a programmer would typically expect.
The reason behind it should be related to type conversion between “byte” and “int” types. With the following workaround:

switch((int)b)

the program executes “proper” case.