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
676
votes
6 answers

Scala vs. Groovy vs. Clojure

Can someone please explain the major differences between Scala, Groovy and Clojure. I know each of these compiles to run on the JVM but I'd like a simple comparison between them.
James Fassett
  • 40,306
  • 11
  • 38
  • 43
392
votes
7 answers

What the difference in applying gradle plugin

I don't understand gradle plugins block apply plugin: 'someplugin1' apply plugin: 'maven' and other one: plugins { id 'org.hidetake.ssh' version '1.1.2' } In first block We have some plugin name. in second one package and version. I don't…
Yevgen Kulik
  • 5,713
  • 2
  • 22
  • 44
357
votes
10 answers

How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later. sh "ls -l" How can I do this, especially as it seems that you cannot really run any kind of…
sorin
  • 161,544
  • 178
  • 535
  • 806
351
votes
6 answers

How to read a file in Groovy into a string?

I need to read a file from the file system and load the entire contents into a string in a groovy controller, what's the easiest way to do that?
raffian
  • 31,267
  • 26
  • 103
  • 174
329
votes
13 answers

Converting a string to int in Groovy

I have a String that represents an integer value and would like to convert it to an int. Is there a groovy equivalent of Java's Integer.parseInt(String)?
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
311
votes
9 answers

Could not find method compile() for arguments Gradle

Looked around for this solution for much too long now, and I'm not sure if I missed it or just misstyped something, but my Gradle script will not compile. I am migrating to Gradle, and am very new with it. I am very used to using Maven for…
Ichbinjoe
  • 3,259
  • 2
  • 12
  • 7
247
votes
4 answers

Jenkins: Can comments be added to a Jenkinsfile?

Are comments possible in a Jenkinsfile? If so, what's the syntax? I am using the declarative pipeline syntax. I want to comment out the "post" section below until my SMTP server is working. pipeline { agent { label 'docker-build-slave' } …
danday74
  • 52,471
  • 49
  • 232
  • 283
217
votes
5 answers

How can I trigger another job from a jenkins pipeline (jenkinsfile) with GitHub Org Plugin?

How can I trigger build of another job from inside the Jenkinsfile? I assume that this job is another repository under the same github organization, one that already has its own Jenkins file. I also want to do this only if the branch name is…
sorin
  • 161,544
  • 178
  • 535
  • 806
214
votes
7 answers

Groovy executing shell commands

Groovy adds the execute method to String to make executing shells fairly easy; println "ls".execute().text but if an error happens, then there is no resulting output. Is there an easy way to get both the standard error and standard output? (other…
Bob Herrmann
  • 9,458
  • 10
  • 38
  • 45
198
votes
6 answers

Groovy: what's the purpose of "def" in "def x = 0"?

In the following piece of code (taken from the Groovy Semantics Manual page), why prefix the assignment with the keyword def? def x = 0 def y = 5 while ( y-- > 0 ) { println "" + x + " " + y x++ } assert x == 5 The def keyword can be…
Leonel
  • 28,541
  • 26
  • 76
  • 103
196
votes
6 answers

Recommended way to stop a Gradle build

How can I stop a Gradle build after detecting a problem? I can use an assert, throw an exception, do a System.exit (bad idea), or use a dedicated function in Gradle (but I could not find one). What is the best way for Gradle (and why?).
Kartoch
  • 7,610
  • 9
  • 40
  • 68
196
votes
4 answers

Loop through Map in Groovy?

I have a very simple task I am trying to do in Groovy but cannot seem to get it to work. I am just trying to loop through a map object in groovy and print out the key and value but this code does not work. // A simple map def map = [ iPhone…
Kevin
  • 2,852
  • 6
  • 21
  • 33
195
votes
9 answers

Groovy Shell warning "Could not open/create prefs root node ..."

I tried to open the Groovy Shell (groovysh) on Windows 8 and got the following output: java.util.prefs.WindowsPreferences WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...)…
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
195
votes
31 answers

Gradle does not find tools.jar

I am using javadoc doclets with gradle, so I need to use the package tools.jar, which is in the lib folder from the jdk (1.6.0_26 in my case). The point is that gradle does not take it automatically, so I was adding that tools package to my libs…
raspayu
  • 5,089
  • 5
  • 37
  • 50
192
votes
17 answers

How can I fix "unsupported class file major version 60" in IntelliJ IDEA?

I have a Gradle project in Ubuntu. It's written in Java 14. I have the Java 14 JDK installed. When I build it from the command line, everything works, but no one wants to use a command line! When I open it in IntelliJ IDEA, it throws an error: *…
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477
1
2 3
99 100