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
78
votes
7 answers

How to set project.version by passing version property on gradle command line?

I want to build JAR with self-defined version passed via command line, such as: When I execute gradle build task like this: gradle build -Pversion=1.0 myproject-1.0.jar should be generated. I have tried adding the line below to the build.gradle,…
pat.inside
  • 1,724
  • 4
  • 17
  • 25
78
votes
31 answers

Hidden features of Groovy?

It seems like Groovy was forgotten in this thread so I'll just ask the same question for Groovy. Try to limit answers to Groovy core One feature per answer Give an example and short description of the feature, not just a link to documentation Label…
anon
78
votes
4 answers

for each loop in groovy

How to implement foreach in Groovy? I have an example of code in Java, but I don't know how to implement this code in Groovy... Java: for (Object objKey : tmpHM.keySet()) { HashMap objHM = (HashMap) list.get(objKey); } I read…
Adrian Adendrata
  • 811
  • 1
  • 6
  • 4
76
votes
6 answers

How do I tell IntelliJ about groovy installed with brew on OSX

I'm running: IntelliJ Ultimate 2016.3 Homebrew 1.1.2 OS X 10.11.5 El Capitan I ran brew install groovy which resulted in groovy being installed in /usr/local/Cellar/groovy/2.4.7/. Brew also added a symlink: /usr/local/bin/groovy ->…
David
  • 14,569
  • 34
  • 78
  • 107
76
votes
10 answers

Jenkins - abort running build if new one is started

I use Jenkins and Multibranch Pipeline. I have a job for each active git branch. New build is triggered by push in git repository. What I want is to abort running builds in current branch if new one appears in same branch. For example: I commit and…
kakty3
  • 1,149
  • 1
  • 9
  • 12
75
votes
4 answers

Is it possible to create object without declaring class?

Is it possible to create object without declaring class? Like in JavaScript obj = {a: '1'}; console.log(obj.a)
fedor.belov
  • 22,343
  • 26
  • 89
  • 134
75
votes
2 answers

How to replace string in Groovy

I have some string like C:\dev\deploy_test.log I want by means of Groovy to convert string to C:/dev/deploy_test.log I try to perform it with command Change_1 = Log_file_1.replaceAll('\','/'); It doesn't convert this string
Bilow Yuriy
  • 1,239
  • 3
  • 13
  • 20
75
votes
11 answers

Jenkins: Pipeline sh bad substitution error

A step in my pipeline uploads a .tar to an artifactory server. I am getting a Bad substitution error when passing in env.BUILD_NUMBER, but the same commands works when the number is hard coded. The script is written in groovy through jenkins and is…
Stephen Nichols
  • 2,363
  • 5
  • 14
  • 19
75
votes
3 answers

ext and code block's meaning in the gradle file

ext { springVersion = "3.1.0.RELEASE" emailNotification = "build@master.org" } Above code is the snippet of build.gradle I understand that call ext method with { } closure parameter. it's right? So I think gradle is accessing springVersion…
uuidcode
  • 3,790
  • 3
  • 25
  • 30
75
votes
7 answers

How to pass parameters or arguments into a Gradle task?

I have a Gradle build script into which I am trying to include Eric Wendelin's CSS plugin. It's easy enough to implement, and because I only want minification (rather than combining and gzipping), I've got the pertinent parts of the build script…
Nathan Russell
  • 3,428
  • 5
  • 30
  • 51
74
votes
9 answers

How to rotate JPEG images based on the orientation metadata?

I have some server code that is generating thumbnails when an image is uploaded. The issue is that when the image was taken and the camera/device was rotated, the thumbnails are rotated, even though the full size images themselves are displayed in…
hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
74
votes
2 answers

Updating environment global variable in Jenkins pipeline from the stage level - is it possible?

I have a Jenkinsfile with some global variables and some stages. can I update the global variable out from a stage? An example: pipeline { agent any environment { PASSWD = "${sh(returnStdout: true, script: 'python -u…
Marvin Kallohn
  • 943
  • 3
  • 9
  • 12
74
votes
4 answers

How to specify when branch NOT (branch name) in jenkinsfile?

How can I specify something like the following in my Jenkinsfile? when branch not x I know how to specify branch specific tasks like: stage('Master Branch Tasks') { when { branch "master" } steps { sh…
HosseinK
  • 1,247
  • 4
  • 13
  • 18
74
votes
7 answers

Groovy String to Date

I am coding this with Groovy I am currently trying to convert a string that I have to a date without having to do anything too tedious. String theDate = "28/09/2010 16:02:43"; def newdate = new Date().parse("d/M/yyyy H:m:s", theDate) Output: Tue…
StartingGroovy
  • 2,802
  • 9
  • 47
  • 66
74
votes
6 answers

Groovy method with optional parameters

I would like to write a wrapper method for a webservice, the service accepts 2 mandatory and 3 optional parameters. To have a shorter example, I would like to get the following code working def myMethod(pParm1='1', pParm2='2') { println…
Chris
  • 1,119
  • 1
  • 8
  • 26