Using Groovy for Vaadin Hilla endpoints

Since version 2 Vaadin Hilla no longer needs endpoints to be .java files to be parsed. Now the endpoints are determined by analyzing the generated classes. So in theory any JVM language can be used now for endpoints - as long as the result comes close enough to what the Java compiler would produce.

For Groovy this means to annotate the @dev.hilla.Enpoint classes with @groovy.transform.stc.POJO and @groovy.transform.CompileStatic.

@CompileStatic is no stranger, but @POJO is new since Groovy 4.0; both combined will result in byte-code, that is very close to what the Java compiler would produce from a similar .java file. Yet you are still able to use Groovy code and annotations.

Complete example:

package com.example.application.helloworld

import com.vaadin.flow.server.auth.AnonymousAllowed
import dev.hilla.Endpoint
import jakarta.annotation.Nonnull
import jakarta.validation.constraints.NotEmpty

@Endpoint
@AnonymousAllowed
@groovy.transform.stc.POJO      // XXX
@groovy.transform.CompileStatic // XXX
class HelloWorldEndpoint {

    private final HelloWorldService helloWorldService

    HelloWorldEndpoint(HelloWorldService helloWorldService) {
        this.helloWorldService = helloWorldService
    }

    @Nonnull
    String sayHello(@NotEmpty String name) {
        return helloWorldService.sayHello(name)
    }
}