Member-only story

Building native Java CLIs with GraalVM, Picocli, and Gradle

Mitch Seymour
6 min readMar 8, 2020

--

Background

The Java ecosystem is evolving in exciting ways. Historically, Java developers who wanted to build standalone CLI programs would have to leave the Java ecosystem and instead use a language like Golang, which can compile source code into light-weight, standalone binaries that are easy to use and distribute.

However, a new ahead-of-time compilation technology called GraalVM gives Java developers the ability to compile Java code into machine code. Building standalone executables (native images) with GraalVM not only allows us to build modern CLI apps with Java, but also improves the portability of our code (binary files are easy to distribute). There are also some performance benefits, as well:

The resulting program has faster startup time and lower runtime memory overhead compared to a Java VM ¹

Furthermore, as GraalVM has matured, so too have Java CLI frameworks. One in particular stands out for its ease of use and large feature list. Picocli makes it easy to build feature-rich CLI applications by simply adding annotations to your Java classes, and includes features like tab completion, command hierarchies, colorized text, interactive password support, and more.

--

--

Mitch Seymour
Mitch Seymour

Responses (1)

Write a response