Questions tagged [groovy]

Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl and Smalltalk. It can be used as a scripting language for the Java platform.

Apache Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax. It integrates smoothly with any program, and immediately delivers to your application powerful features, including scripting capabilities, Domain-Specific Language authoring, runtime and compile-time meta-programming and functional programming.

Groovy is an object-oriented, agile and dynamic language for the Java Virtual Machine. It builds upon the strengths of but has additional power features inspired by languages like , and . It makes modern programming features available to developers with almost zero learning curve. It can be used as a scripting language for the Platform. From Wikipedia

Flat learning curve:

Concise, readable and expressive syntax, easy to learn for developers

Powerful features:

Closures, builders, runtime & compile-time meta-programming, functional programming, type inference, and static compilation

Smooth Java integration:

Seamlessly and transparently integrates and interoperates with and any third-party libraries

Domain-Specific Languages:

Flexible & malleable syntax, advanced integration & customization mechanisms, to integrate readable business rules in your applications

Vibrant and rich ecosystem:

Web development, reactive applications, concurrency / asynchronous / parallelism library, test frameworks, build tools, code analysis, GUI building

Scripting and testing glue:

Great for writing concise and maintainable tests, and for all your build and automation tasks

Hello World

println 'Hello World'

Tools

Online Resources

Groovy compared to other languages

On January 19, 2015 Pivotal announced end of their sponsorship to Groovy and Grails. Groovy was then submitted to become a project at the Apache Software Foundation. On November 18, 2015 the Groovy project graduated from Apache Project Incubation becoming an official Apache project.

29887 questions
8
votes
2 answers

How to have optional named arguments in Groovy method

Using the documented mixture of named and positional arguments (or args with default values for that matter), how to invoke a method without specifying any named param? I'm trying to extend existing shared method without breaking everybody else's…
Sunny Milenov
  • 21,990
  • 6
  • 80
  • 106
8
votes
4 answers

compiling Java and groovy with java 11

Does anyone know which compiler/plugin compiles java and groovy code with the java 11 version? I've tried GMavenPlus, Groovy eclipse compiler, and Maven’s Ant plugin. So far without success.
Petronella
  • 2,327
  • 1
  • 15
  • 24
8
votes
4 answers

GroovyDoc as Maven Plugin

Is there a maven plugin available somewhere that utilizes GroovyDoc, preferably as a report? I guess GMaven would be the place to look but the docs are ancient (1.0, whereas the current version is 1.3) and the GMaven plugin doesn't have any mojo…
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
8
votes
2 answers

grails plugin repositories

By default, the following repositories are configured in BuildConfig.groovy repositories { grailsPlugins() grailsHome() // look inside the grails installation grailsCentral() } I understand that the grailsHome() repository…
Dónal
  • 185,044
  • 174
  • 569
  • 824
8
votes
1 answer

Is there an API for grep, pipe, cat in groovy?

Is there an API for grep, pipe, cat in groovy?
Espen Schulstad
  • 2,355
  • 3
  • 21
  • 32
8
votes
2 answers

How to write an XML to file, with just a Parser instance?

This is my Groovy code: // ... def xml = new XmlParser().parse(fileName) xml.each { e -> // some changes are being made to XML xml.append("test", "test me") } def writer = new FileWriter(newFileName) new XmlNodePrinter(new…
yegor256
  • 102,010
  • 123
  • 446
  • 597
8
votes
4 answers

jenkins shared library error com.cloudbees.groovy.cps.impl.CpsCallableInvocation

I run this code through jenkins pipeline(shared library). enum Components { service('name_api') Components(String componentName) { this.componentName = componentName } private String componentName String getComponentName() { …
element
  • 111
  • 1
  • 8
8
votes
1 answer

grails using uuid as id and mapping to to binary column

I want to use a UUID for the id for my domain objects. The idea is that the uuid could be provided by a client and if not a UUID will be generated. I have the definition as like so : : class Person { static mapping = { id…
imrank1
  • 629
  • 1
  • 6
  • 16
8
votes
3 answers

Integrating Groovy with Java

I am currently working on integrating Groovy with an existing Java project. The Groovy script basically parses XML into objects and then will use existing DAO's to save, update, etc. I have 2 projects. One groovy. One java. Using Maven (I used the…
Ken
  • 171
  • 1
  • 6
8
votes
2 answers

groovy.lang.MissingMethodException: No signature of method: sh() is applicable for argument types while testing AWS CLI commands in Groovy

$ groovy --version Groovy Version: 2.4.15 JVM: 1.8.0_171 Vendor: Oracle Corporation OS: Mac OS X I want execute some AWS CLI commands in Groovy, eventually in a Jenkinsfile to run in Jenkins of course. But for prototyping, I want to code it on my…
Chris F
  • 14,337
  • 30
  • 94
  • 192
8
votes
0 answers

Implement methodMissing() for closure delegate

I'm trying to implement a somewhat general DSL with Java and Groovy. The idea is to have a syntax like data { name 'my name' } and to intercept all the method calls with methodMissing where I can check that the method name equals to a field and set…
Andrew Sokolov
  • 277
  • 2
  • 12
8
votes
3 answers

How do you disable Jenkins CSRF with script?

I'm having issues disabling the CSRF protection in an automated fashion. I want to disable with a groovy init script or just in a property file before Jenkins Master Starts. I'm not sure why I'm getting a crumb issue I assume it has to do with the…
Grant Zukel
  • 1,153
  • 2
  • 24
  • 48
8
votes
5 answers

Good alternative to Windows batch scripts?

What are some good alternatives to Windows batch scripts? We have a number of them and they are very "clunky" to work with. As our group is familiar with Java is Groovy a good option? A lot of our scripts are used to prep dev databases so they…
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
8
votes
0 answers

How to get file from resources directory from groovy jar library

I'm not being able to read a JSON file within resources directory from my project's compiled jar. But... first things first: I've created a 'Gradle Groovy' Project within Intellij idea (v2017.3.4 Community Edition) with the following structure: So,…
Cristian Gonçalves
  • 892
  • 2
  • 9
  • 18
8
votes
2 answers

Exception in declaring a json with dynamic values in Jenkinsfile

def props = readJSON text: [ 'buildName':"${params.buildName}", 'targetRepo':"${params.artifactoryReleases}"] echo props.buildName echo props.targetRepo Getting the following error org.kohsuke.stapler.NoStaplerConstructorException: There's no…
Sankarganesh Eswaran
  • 10,076
  • 3
  • 23
  • 24