Micronaut Groovy

Projects that enhance the Micronaut and Groovy language experience

Version: 4.3.1-SNAPSHOT

1 Introduction

This project includes various subprojects that improve the Micronaut experience for Groovy users.

2 Release History

For this project, you can find a list of releases (with release notes) here:

3 Groovy Configuration

The micronaut-runtime-groovy module adds the ability to use Groovy to define configuration.

To use this module add the micronaut-runtime-groovy to your build configuration:

implementation("io.micronaut.groovy:micronaut-runtime-groovy")
<dependency>
    <groupId>io.micronaut.groovy</groupId>
    <artifactId>micronaut-runtime-groovy</artifactId>
</dependency>

You can then define configuration Groovy config in src/main/resources/application.groovy in ConfigSlurper format. Because property names in a ConfigSlurper configuration file must be valid Groovy identifiers and cannot contain dashes, you can specify configuration entries either by converting them to camel-case or snake-case.

application.groovy
//set server-url property
serverUrl = "https://localhost:8080"
//alternatively
server_url = "https://localhost:8080"

4 Groovy Functions

The micronaut-function-groovy adds the ability to define Serverless functions as Groovy scripts.

If you have the Micronaut CLI installed you can quickly create a Groovy function with mn create-function hello-world --lang groovy

To begin, add the function-groovy dependency (instead of the provider-specific dependency) which provides additional AST transformations that make writing functions simpler. For example, in build.gradle:

implementation("io.micronaut.groovy:micronaut-function-groovy")
<dependency>
    <groupId>io.micronaut.groovy</groupId>
    <artifactId>micronaut-function-groovy</artifactId>
</dependency>

You can now create your function as a Groovy script, under src/main/groovy. You will set your project’s main class property to this function (instead of FunctionApplication as in Java/Kotlin). For example:

Example build.gradle
mainClassName = "example.HelloGroovyFunction"
HelloGroovyFunction.groovy
String hello(String name) {
    "Hello ${name}!"
}

The function you define should follow the following rules:

  1. Define no more than 2 inputs

  2. Use either Java primitive or simple types or POJOs as the arguments and return values

In order to make use of dependency injection in your Groovy function, use the groovy.transform.Field annotation transform in addition to the @Inject annotation.

HelloGroovyFunction.groovy
import groovy.transform.Field
import javax.inject.Inject

@Field @Inject HelloService helloService

String hello(String name) {
    helloService.hello(name)
}

5 GORM

Micronaut Framework 4 uses Groovy 4 and it does not support GORM 7. Micronaut Groovy will support GORM once there is a GORM version built with Groovy 4.

6 Repository

You can find the source code of this project in this repository: