Skip to content

Example CLI app written in Groovy, using micronaut, compiling into a static binary via Graal native image

License

Notifications You must be signed in to change notification settings

cloudogu/groovy-cli-graal-nativeimage-micronaut-example

Repository files navigation

Groovy CLI Graal Native Image Micronaut Example

Push to GitHub Container Registry

An example CLI app written in Groovy, using micronaut, compiling into a static binary via Graal native image.

Use of GraalVM’s native-image tool is only supported in Java or Kotlin projects. Groovy relies heavily on reflection which is only partially supported by GraalVM.
https://docs.micronaut.io/2.5.1/guide/index.html#graal

This project is for those who'd like to try anyway.

Create and run image

The result can also be found at ghcr.io/cloudogu/groovy-cli-graal-nativeimage-micronaut-example

# First build takes a couple of minutes!
$ docker build -t groovy .

# Run image built locally
$ docker run --rm groovy -v
# Or pull and run remote image
$ docker run --rm ghcr.io/cloudogu/groovy-cli-graal-nativeimage-micronaut-example

# Interesting: Size of static Binary without additional JRE (uncompressed! on the registry it's about 1/4 the size)
$ docker images groovy
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
groovy          latest    c5f9ff7e61c6   50 minutes ago   76.9MB

The build should also work without Dockerfile using ./mvnw package -Dpackaging=docker-native but this fails. Passing the same arguments as in Dockerfile also fails:

# java.lang.NoClassDefFoundError: org/apache/ivy/core/module/descriptor/ModuleDescriptor
./mvnw package -Dpackaging=docker-native \
  -Dmicronaut.native-image.args='-Dgroovy.grape.enable=false -H:+ReportExceptionStackTraces -H:ConfigurationFileDirectories=conf/ --static --allow-incomplete-classpath --report-unsupported-elements-at-runtime --initialize-at-run-time=org.codehaus.groovy.control.XStreamUtils,groovy.grape.GrapeIvy --initialize-at-build-time --no-server'

So somehow some dependencies seem to be missing?!

How this example was created

mn create-cli-app -b maven -l groovy -t junit groovy 

Manually added

  • pom.xml:
    • for <artifactId>gmavenplus-plugin</artifactId>
      <configuration>
        <configScript>compiler.groovy</configScript>
      </configuration>
      • Add maven.compiler.source and .target to use JDK 11
  • Dockerfile and .dockerignore
  • compiler.groovy
  • for development it would also be helpful to set the compiler.groovy as the config script for your IDE's groovy compiler.

Resources

About

Example CLI app written in Groovy, using micronaut, compiling into a static binary via Graal native image

Topics

Resources

License

Stars

Watchers

Forks

Packages