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
137
votes
3 answers

Jenkins pipeline how to change to another folder

Currently i am using Jenkins pipeline script. For running one command, I need to access a folder outside its workspace directory. I tried sh "cd $workspace/", but it returned current workspace folder. How I can change to root workspace directory…
wanderors
  • 2,030
  • 5
  • 21
  • 35
134
votes
2 answers

How to use a variable for the key part of a map

Let's say I have def A = "abc" def X = "xyz" how do I create a Map where, instead of def map = [A:1, X:2] I get instead the equivalent of writing def map = [abc:1, xyz:2] but can use a variables A and X for the key? P.S.: Same question for the…
Ray
  • 5,885
  • 16
  • 61
  • 97
133
votes
6 answers

What are the key differences between Scala and Groovy?

On the surface Groovy and Scala look pretty similar, aside from Scala being statically typed, and Groovy dynamic. What are the other key differences, and advantages each have over the other? How similar are they really? Is there competition…
Leif
  • 1,431
  • 2
  • 10
  • 8
133
votes
3 answers

What's the difference of strings within single or double quotes in groovy?

def a = "a string" def b = 'another' Is there any difference? Or just like javascript to let's input ' and " easier in strings?
Freewind
  • 193,756
  • 157
  • 432
  • 708
130
votes
16 answers

'dependencies' cannot be applied to '(groovy.lang.Closure)'

I am unable to fix this error: dependencies cannot be applied to '(groovy.lang.Closure) This is my gradle file: buildscript { repositories { maven { url 'http://download.crashlytics.com/maven' } } dependencies { …
Ashwani Kottapalli
  • 1,322
  • 2
  • 8
  • 7
124
votes
5 answers

Resetting the UP-TO-DATE property of gradle tasks?

Is there a way I can force a gradle task to run again, or reset all tasks back to the not UP-TO-DATE state?
Stefan Kendall
  • 66,414
  • 68
  • 253
  • 406
123
votes
5 answers

Configuring Groovy SDK within IntelliJ IDEA

I am running IntelliJ IDEA 2017.2.3. I installed Groovy 2.4.12 via Homebrew (OS X). When I open a Groovy source file (or a Jenkinsfile), I get the following: Groovy SDK is not configured for module 'my-module' . . . . . Configure Groovy…
Carl Patenaude Poulin
  • 6,238
  • 5
  • 24
  • 46
121
votes
8 answers

shortcut for creating a Map from a List in groovy?

I'd like some sorthand for this: Map rowToMap(row) { def rowMap = [:]; row.columns.each{ rowMap[it.name] = it.val } return rowMap; } given the way the GDK stuff is, I'd expect to be able to do something like: Map rowToMap(row) { …
danb
  • 10,239
  • 14
  • 60
  • 76
119
votes
13 answers

Including a groovy script in another groovy

I have read how to simply import a groovy file in another groovy script I want to define common functions in one groovy file and call those functions from other groovy files. I understand this would be using Groovy like a scripting language i.e, I…
Kannan Ekanath
  • 16,759
  • 22
  • 75
  • 101
115
votes
13 answers

Jenkins Pipeline NotSerializableException: groovy.json.internal.LazyMap

Solved: Thanks to below answer from S.Richmond. I needed to unset all stored maps of the groovy.json.internal.LazyMap type which meant nullifying the variables envServers and object after use. Additional: People searching for this error might be…
Sunvic
  • 1,521
  • 2
  • 10
  • 13
113
votes
5 answers

How can I import one Gradle script into another?

I have a complex Gradle script that wraps up a load of functionality around building and deploying a number of NetBeans projects to a number of environments. The script works very well, but in essence it is all configured through half a dozen maps…
Anthony Roy
  • 1,835
  • 3
  • 15
  • 16
111
votes
4 answers

Failing a build in Jenkinsfile

Under certain conditions I want to fail the build. How do I do that? I tried: throw RuntimeException("Build failed for some specific reason!") This does in fact fail the build. However, the log shows the…
oillio
  • 4,748
  • 5
  • 31
  • 37
111
votes
7 answers

Groovy built-in REST/HTTP client?

I heard that Groovy has a built-in REST/HTTP client. The only library I can find is HttpBuilder, is this it? Basically I'm looking for a way to do HTTP GETs from inside Groovy code without having to import any libraries (if at all possible). But…
smeeb
  • 27,777
  • 57
  • 250
  • 447
111
votes
6 answers

Splitting String with delimiter

I am currently trying to split a string 1128-2 so that I can have two separate values. For example, value1: 1128 and value2: 2, so that I can then use each value separately. I have tried split() but with no success. Is there a specific way Grails…
thehoule64
  • 1,761
  • 5
  • 15
  • 22
109
votes
7 answers

Groovy - How to compare the string?

how to compare the string which is passed as a parameter the following method is not working. String str = "saveMe" compareString(str) def compareString(String str){ def str2 = "saveMe" if(str2==${str}){ println "same" …
user1602802
  • 1,139
  • 2
  • 8
  • 7