Search code examples
groovyexecutable-jargraalvmpicocli

How to convert picocli groovy-grape script to native standalone app?


I have a made my first groovy CLI app with picocli. Now, I want it to be available for use without any JVM installed on the client machine, maybe with the use of GraalVM. This is for an opensource project: https://github.com/kchaitanya863/db2csv


Solution

  • You will need to:

    • statically compile your groovy script
    • make the args variable available after static compilation with
    final String[] args = getProperty("args") as String[]
    
    • specify a reflection configuration file for the classes dynamically loaded/invoked using reflection by Groovy (this may be useful)
    • specify a reflection configuration file for the classes loaded/invoked using reflection by picocli. The picocli-codegen module provides a picocli.codegen.aot.graalvm.ReflectionConfigGenerator tool to generate the configuration file.
    • If your script has any @Grape dependencies, you may need to turn off the Grape dependency manager with -Dgroovy.grape.enabled=false and add all dependencies to the classpath manually instead

    Credit: I got most of these tips from this article by Szymon Stepniak