0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · Lezione

Script Groovy e GShell

Impari a scrivere ed eseguire script Groovy e a interagire con la console Groovy (GroovyShell).

Script Groovy e GShell è una lezione Groovy & Gradle: JVM Automation and Build Engineering gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Groovy & Gradle: JVM Automation and Build Engineering, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Groovy & Gradle: JVM Automation and Build Engineering include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

Groovy Scripts: Quick Automation

A Groovy script is just a file of code that runs directly — no main method required. Perfect for automation and quick utilities.

Simple Script Structure

A Groovy script needs no class or method wrapper — the file itself is the entry point. Just write your lines and run them.

println "Hello from a Groovy script!"
def name = "Coddy"
println "My name is $name"

Executing Groovy Scripts

Save your code with a .groovy extension, then run it from the terminal with groovy myScript.groovy. That is the whole workflow.

Script Example: Basic Calculation

This script adds two numbers and branches with an if — a quick taste of how natural and readable Groovy scripting feels.

def num1 = 10
def num2 = 5
def sum = num1 + num2
println "The sum of $num1 and $num2 is: $sum"

if (sum > 10) {
  println "That's a big sum!"
}

Getting User Input

Scripts can talk to the user too. Read a line from the console with System.in.newReader().readLine(), as shown below.

print "What's your name? "
def name = System.in.newReader().readLine()
println "Hello, $name! Welcome to Groovy."

Meet the GroovyShell (GShel)

The GroovyShell (groovysh) is an interactive console — run snippets instantly, test ideas, and get feedback without saving a file.

Launching GShell

Type groovysh to launch the interactive shell, or groovyConsole for the GUI version. We will stick with the command-line one here.

Your First GShell Commands

Inside groovysh, type any Groovy and it runs immediately, showing the result after ===>. Type :exit when you are done.

GShell: Beyond Code

GShell has colon commands for managing your session: :help, :history, :clear, and :reset to wipe declared variables.

Instant Code Testing

GShell shines for instant experiments — call a method or transform a list and see the result right away, no file, compile, or run step.

Script vs. GShell

Consider the following Groovy code snippet:

def x = 5
println x * 2

Where would you typically execute this snippet if you want to save it for later use and run it repeatedly?

Recap: Scripts & GShell

You learned the two core Groovy tools: scripts for repeatable .groovy files, and the GroovyShell for instant experimentation.

Domande Frequenti

La lezione «Script Groovy e GShell» è gratuita?

Sì — il testo completo di «Script Groovy e GShell» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Groovy & Gradle: JVM Automation and Build Engineering, passa a CoddyKit PRO. Il corso Groovy & Gradle: JVM Automation and Build Engineering include 4 lezioni in totale.

Cosa imparerò in «Script Groovy e GShell»?

Impari a scrivere ed eseguire script Groovy e a interagire con la console Groovy (GroovyShell). Eserciti Groovy & Gradle: JVM Automation and Build Engineering con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Groovy & Gradle: JVM Automation and Build Engineering?

Non è richiesta alcuna esperienza precedente. Groovy & Gradle: JVM Automation and Build Engineering su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.

Quanto tempo richiede la lezione «Script Groovy e GShell»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Groovy & Gradle: JVM Automation and Build Engineering?

Sì. Ogni lezione Groovy & Gradle: JVM Automation and Build Engineering include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Introduzione a Groovy e alla JVM
  2. Sintassi e tipi di base di Groovy
  3. Script Groovy e GShell
  4. Stringhe Groovy e GString
← Torna a Groovy & Gradle: JVM Automation and Build Engineering