Interactive command-line shell (REPL) for Apache Groovy with scripting engine and rich command system
npx @tessl/cli install tessl/maven-org-apache-groovy--groovy-groovysh@5.0.0Apache Groovy's interactive command-line shell (REPL) that provides a powerful environment for evaluating Groovy expressions, defining classes, and running experiments interactively. Built on JLine3, it offers rich cross-platform line editing capabilities with history, tab completion, ANSI color support, and a robust command system with online help and user alias support.
implementation 'org.apache.groovy:groovy-groovysh:5.0.0'import org.apache.groovy.groovysh.jline.GroovyEngine
import org.apache.groovy.groovysh.MainFor programmatic usage:
import org.apache.groovy.groovysh.jline.GroovyEngine;
import org.apache.groovy.groovysh.jline.GroovyConsoleEngine;
import org.apache.groovy.groovysh.jline.GroovySystemRegistry;# Start interactive shell
groovysh
# Execute code and exit
groovysh --evaluate "println 'Hello World'"
# Load script file
groovysh --evaluate "load 'script.groovy'"import org.apache.groovy.groovysh.jline.GroovyEngine
// Create and configure engine
GroovyEngine engine = new GroovyEngine()
// Execute Groovy code
Object result = engine.execute("2 + 2")
println result // 4
// Manage variables
engine.put("name", "World")
Object greeting = engine.execute("'Hello, ' + name")
println greeting // "Hello, World"
// Check and retrieve variables
if (engine.hasVariable("name")) {
Object value = engine.get("name")
println "Name: $value"
}Groovysh is built around several key components:
Main class provides command-line interface with comprehensive option parsingGroovyEngine handles code execution, variable management, and state persistenceGroovyConsoleEngine and GroovySystemRegistry manage REPL interaction and command processingCore engine for executing Groovy code programmatically, managing variables, imports, and providing code completion. Essential for embedding Groovy REPL functionality in applications.
class GroovyEngine {
Object execute(String statement)
Object execute(File script, Object[] args)
Object execute(Object closure, Object... args)
void put(String name, Object value)
Object get(String name)
boolean hasVariable(String name)
Map<String, Object> find(String name)
void reset()
}Built-in shell commands for file operations, object inspection, documentation lookup, dependency management, and state control. These commands provide a rich interactive development environment.
// File operations
/load [options] [file] // Load script file or saved state
/save [options] [file] // Save current state or buffer
/slurp [options] file // Parse structured data files
// Development tools
/inspect [options] object // Inspect object properties and methods
/doc object // Open documentation in browser
/grab coordinates // Add Maven dependencies
// State management
/vars [name] // Show or delete variables
/imports [name] // Show or delete imports
/reset // Clear all stateAdvanced console features including syntax highlighting, auto-completion, custom command registration, and integration with JLine3 terminal capabilities.
class GroovyConsoleEngine {
void println(Map<String, Object> options, Object object)
}
class GroovySystemRegistry {
Object execute(String line)
boolean isCommandOrScript(String command)
}Tools for exploring objects, browsing documentation, and understanding code structure during interactive development sessions.
class ObjectInspector {
// Object introspection utilities
}
class DocFinder {
// Documentation URL resolution
}// Core engine options
interface GroovyOptions {
boolean CANONICAL_NAMES
boolean NO_SYNTAX_CHECK
boolean RESTRICTED_COMPLETION
boolean ALL_METHODS_COMPLETION
boolean ALL_FIELDS_COMPLETION
boolean ALL_CONSTRUCTORS_COMPLETION
boolean IDENTIFIERS_COMPLETION
boolean META_METHODS_COMPLETION
boolean SYNTHETIC_METHODS_COMPLETION
}
// Data serialization formats
enum SerializationFormat {
JSON, NONE
}
enum DeserializationFormat {
JSON, GROOVY, NONE
}