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

Scripts Groovy e GShell

Aprenda a escrever e executar scripts Groovy e a interagir com o console Groovy (GroovyShell).

Scripts Groovy e GShell é uma aula grátis de Groovy & Gradle: JVM Automation and Build Engineering no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Groovy & Gradle: JVM Automation and Build Engineering, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Groovy & Gradle: JVM Automation and Build Engineering inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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.

Perguntas Frequentes

A aula “Scripts Groovy e GShell” é grátis?

Sim — o texto completo de “Scripts Groovy e GShell” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Groovy & Gradle: JVM Automation and Build Engineering, atualize para CoddyKit PRO. O curso de Groovy & Gradle: JVM Automation and Build Engineering inclui 4 aulas no total.

O que vou aprender em “Scripts Groovy e GShell”?

Aprenda a escrever e executar scripts Groovy e a interagir com o console Groovy (GroovyShell). Você pratica Groovy & Gradle: JVM Automation and Build Engineering com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Groovy & Gradle: JVM Automation and Build Engineering?

Nenhuma experiência prévia é necessária. Groovy & Gradle: JVM Automation and Build Engineering no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Scripts Groovy e GShell”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Groovy & Gradle: JVM Automation and Build Engineering?

Sim. Cada aula de Groovy & Gradle: JVM Automation and Build Engineering inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Introdução a Groovy e à JVM
  2. Sintaxe e tipos básicos de Groovy
  3. Scripts Groovy e GShell
  4. Cadeias de Texto Groovy e GStrings
← Voltar para Groovy & Gradle: JVM Automation and Build Engineering