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 replace backslashes to slashes for ${basedir} property in maven profile profile

I have a pom.xml with defined property module.basedir that is intended to contain transformed basedir property. It is defined as follows: ${basedir} And I have following code that is…
Igor Nikolaev
  • 4,597
  • 1
  • 19
  • 19
8
votes
3 answers

Fail hudson build with groovy script

I have a couple of post build actions that I run on my Hudson build. They are currently bash scripts, and if I want to fail the biuld from them, I just return a non-zero value. Is there a way to fail the build from another scripting language (such…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
8
votes
1 answer

Jenkins Pipeline currentBuild duration time returns always 0

I am trying to get build duration for our report but it always returns 0. From reading docs, going through Slack plugin source and reading other resources I should be able to do one of the following: def duration = currentBuild.duration def duration…
Tomas
  • 2,676
  • 5
  • 41
  • 51
8
votes
2 answers

Groovy, Netbeans and Java EE

I want to develop a web application (no frameworks) mixing java with groovy. I am using the IDE Netbeans with the plugin. If I start a new Java SE project and add a groovy class, it works with no problems.. but when I create a new java EE project…
José Leal
  • 7,989
  • 9
  • 35
  • 54
8
votes
3 answers

Retrieve Groovy Closure/Method parameters list

How do we retrieve the list of parameters of a closure/method in groovy dynamically, javascript style through the arguments array say for example that i want to log a message this way def closure = {name,id -> log.debug "Executing method with…
ken
  • 3,745
  • 6
  • 34
  • 49
8
votes
3 answers

Spock Error:Groovyc: Could not instantiate global transform class

I m new to Spock, tried to write a simple Spock but it failed: Error:Groovyc: Could not instantiate global transform class org.spockframework.compiler.SpockTransform specified at…
user468587
  • 4,799
  • 24
  • 67
  • 124
8
votes
2 answers

How to print each element of Multi-line String Parameter?

I've Pipeline job in Jenkins (v2.7.1) where I'd like to print each element of Multi-line String parameter (Params) with 3 strings in each line: Foo, Bar, Baz as an input. So I've tried the following syntax (using split and…
kenorb
  • 155,785
  • 88
  • 678
  • 743
8
votes
1 answer

Out of Memory: metaspace with wildfly and groovy/jasper

On our Wildfly 10 applicationserver we are using groovy for jasperreports and other similiar systems. After some time the jvm (java 8) gets an "Out of Memory: metaspace" error. The same issue happens on some older jboss 4 servers with permgen (java…
Hauke Kern
  • 91
  • 6
8
votes
11 answers

Version increment using gradle task

I want to increase the version number of my project from 1.0.0. to 1.0.1 automatically whenever a new build is made through bash command. I only need to increase path number and others i will be increasing manually during manual build. i want to…
Sidharth
  • 1,402
  • 2
  • 16
  • 37
8
votes
2 answers

Groovy: Parsing JSON file

I am quite new to Groovy and I am parsing a JSON file with following code: void getItemData() { def jsonSlurper = new JsonSlurper() def reader = new BufferedReader(new InputStreamReader(new FileInputStream("data.json"),"UTF-8")); data =…
Mahbub Rahman
  • 1,295
  • 1
  • 24
  • 44
8
votes
3 answers

Execute my groovy script with ant or maven

I have the following: 1 java class 1 bat file (starts the groovy script) 1 groovy file All in the same folder. Now I want to use Maven or Ant to run the groovy file but I can't get it to work. Is there someone who can show me how to write this…
Mikael
  • 173
  • 2
  • 12
8
votes
2 answers

Why Map does not work for GString in Groovy?

With the following snippet I cannot retrieve gString from a map: def contents = "contents" def gString = "$contents" def map = [(gString): true] assert map.size() == 1 // Passes assert gString.hashCode() == map.keySet().first().hashCode() //…
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
8
votes
4 answers

GPathResult to String without XML declaration

I'm converting GPathResult to String using def gPathResult = new XmlSlurper().parseText('') XmlUtil.serialize(gPathResult) It works fine, but I'm getting XML declaration in front of my XML How…
Michal Kordas
  • 10,475
  • 7
  • 58
  • 103
8
votes
4 answers

"Class already exists" error in IntelliJ on Groovy class

in IntelliJ (2016.2 and previous) we have our Groovy classes marked red with the error "class already exists". I think we can exclude that the cause is the stub-generation, as this is deactivated. Probably it's caused in our constellation: We have…
Ed O Neill
  • 169
  • 2
  • 11
8
votes
2 answers

Jenkinsfile: Define and assign values to several variables at once seems not to be implemented

I am using Jenkins 2.6 on Red Hat Linux. I want to use the following in my Jenkinsfile, but when I try, Jenkins complains bitterly. (It seems only to dislike the syntax on left-hand side of the = operator.): def (a, b) = [6, 7] It doesn't like…
Will
  • 1,509
  • 1
  • 13
  • 16