DEV Community

Attila Bagossy
Attila Bagossy

Posted on

mvnx - The npx of the JVM world.

From one-off command execution to daily use, command-line tools are indispensable parts of the software engineer's toolbelt. Every popular programming language has a framework for at least argument parsing, but most also offer components for more complex requirements such as prompting or colored output. However, deployment of CLIs is where language ecosystems differ.

The Problem with JVM CLIs

Want to write a CLI in JavaScript? Easy! Just pick some libraries, translate your idea to code, upload to npm (or any other package registry), and you're all set. Anyone can now deploy and use your CLI with the help of npx.

Now, what about the JVM? You pick some libraries, write the code, and upload the artifact to a maven registry. If you were writing a JavaScript library, you'd be out counting the downloads on Not in the case of a JVM CLI, though. There's no standard tool for downloading and executing runnable JARs residing in maven repositories. Thus, despite the general availability of your artifact, it takes quite a bit of effort to obtain and execute your CLI.

Enter mvnx

Having written a few Kotlin CLIs in the past months, I decided to take on this situation. I created mvnx, which boldly claims to address the execution of JARs available in maven repositories:

Inspired by npx, mvnx takes the maven coordinates of an artifact and handles the rest. Watch:

Cowsay on the JVM

If you don't want to enforce a specific version, then you may omit the version coordinate altogether! In this case, mvnx will obtain the latest version.

$ mvnx -q com.github.ricksbrown:cowsay "Hello, World"

By default, mvnx will query the Central Repository. You can alter this behavior by specifying a custom repository URL with support for HTTP Basic authentication credentials and aliases.

Pro tip: mvnx loves GitHub Packages!

Wrapping Up

The JVM ecosystem offers a plethora of excellent libraries, along with stable dependency management solutions. Building upon these foundations, CLIs were easy to write and distribute, but hard to get and execute. mvnx aims to be the missing link between CLI authors and consumers.

Top comments (0)