NEW COURSE 👨🏼‍🏫 Up and Running with Vue.js is available! 🎉 Get it now!

Groovy Command Line Arguments

December 20, 2019 • ☕️ 1 min read

I can't speak for everyone but for me one of the features that really got me excited about the Groovy Programming Language was just how easy it was to get things done. While Java can be verbose at times Groovy cuts down on that and gives us the ability to create a quick script and execute it. What happens if you want to execute a script in Groovy and pass command line arguments to it? That is exactly what we are going to cover in this post.

I recently had a student in my Groovy course ask me a question about command line arguments and I thought it would share it with you.

Hi Dan Vega. Can you pls help me on sample groovy script for command line argument
def test(topic){
    println topic
}

In above program how can I pass topic from command line

First off thank you for not only taking the course but also for asking this question. I think when developers see just how easy it is to start scripting in Groovy one thing you will end up doing is passing arguments to your script. I am going to answer the students question about command line arguments in a Groovy Script but then I will also discuss what you should do if you start to expand on this concept and want to build full blow command-line interface (CLI) applications.

Caution: Shameless plug ahead! Continue reading below
THIS IS AN AD FOR MY GROOVY COURSE

Groovy Command Line Arguments

Groovy Command Line Arguments

create a groovy script how to pass command line arguments to a script how to access the arguments

mention the cli builder if you're going to build a cli app http://docs.groovy-lang.org/latest/html/gapi/groovy/cli/picocli/CliBuilder.html

Follow me on Twitter, LinkedIn, or sign up for my newsletter.

Dan Vega

I’m a Husband, Father, Curriculum Developer and maker of things from Cleveland Ohio. I created this website as a place to document my journey as I learn new things and share them with you. I have a real passion for teaching and I hope that one of blog posts, videos or courses helps you solve a problem or learn something new.