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
1 answer

Groovy script for Jenkins: execute HTTP request without 3rd party libraries

I need to create a Groovy post build script in Jenkins and I need to make a request without using any 3rd party libraries as those can't be referenced from Jenkins. I tried something like this: def connection = new URL(…
George Cimpoies
  • 884
  • 2
  • 14
  • 26
8
votes
1 answer

'final' keyword in Groovy

Is this a bug or a deliberate design decision by the folks at Groovy? final String x = "a" x = "b" You run this and it would work, no problem. Shouldn't a runtime exception be thrown instead? Annotating the class with @CompileStatic didn't help…
Ankush92
  • 401
  • 1
  • 9
  • 20
8
votes
2 answers

No suitable ClassLoader found for grab in Jenkins pipeline script

I'm running into a problem while writing a Jenkins pipeline script. This is the code in my Jenkins pipeline script: @Grab(group='org.postgresql', module='postgresql', version='42.1.4') import groovy.sql.Sql; import java.util.ServiceLoader; import…
안성민
  • 163
  • 1
  • 1
  • 5
8
votes
2 answers

Task 'install' not found in root project gradle

I am trying to convert my Gradle project to Maven using Maven plugin. I am following this SO link but when I ran the Gradle install command I got the following error C:\Users\>gradle install FAILURE: Build failed with an exception. * What went…
LowCool
  • 1,187
  • 5
  • 25
  • 51
8
votes
2 answers

Passing variables to powershell script block in a jenkins pipeline

Is there a way to use groovy variables inside a powershell script? My sample script is as following.. node { stage('Invoke Installation') { def stdoutpowershell def serverName = env.fqdn withEnv(['serverName = $serverName']) { echo…
cansin aldanmaz
  • 119
  • 1
  • 5
  • 10
8
votes
2 answers

Grails: why is the Config.groovy file executed during compilation?

From the Grails documentation and this question: For general configuration Grails provides two files: grails-app/conf/BuildConfig.groovy grails-app/conf/Config.groovy Both of them use Groovy's ConfigSlurper syntax. The first, BuildConfig.groovy,…
user2738748
  • 1,106
  • 2
  • 19
  • 36
8
votes
4 answers

How to get day from date using groovy

I want to get day (Ex Sun, Mon, Tue, ..) from date def date = new Date() def day = date[Calendar.DAY_OF_MONTH] result is 18, but i want to get Mon. And if I have 2017-10-09T00:00:00.000, I want to get day of 2017-10-09T00:00:00.000 Could you help…
Bell Aimsaard
  • 483
  • 3
  • 5
  • 16
8
votes
1 answer

Groovy and Java support matrix

To understand which Java / Groovy combinations will work, I'm looking for a matrix that will show this information. Both on http://www.groovy-lang.org/ and by Googling I wasn't able to find such a matrix. Does anyone have this information available?…
JohanKees
  • 669
  • 1
  • 12
  • 22
8
votes
2 answers

Jenkins launch job through DSL and do not wait for job to finish

Im trying to launch a project through Jenkins DSL but dont need to wait for it to complete. Basically i want it to kick off an orphan job. node("slave-node") { // Launch pipeline job stage("LaunchPipelineJob") { // this step runs…
Lukas Gravley
  • 81
  • 1
  • 4
8
votes
1 answer

curl - How to get a cookie from after login to send in a curl command?

I want to get access to a json page that contains data. Say, it's there under http://example.com/home/apples.json It's protected, so a login page is shown. If I were to visit it manually I first go to http://example.com/ There I get a login menu…
kumoyadori
  • 337
  • 2
  • 10
  • 21
8
votes
0 answers

How to show test coverage, when using Spock to test Java code?

We have a Java project where the unit tests are written using Spock (Groovy). We use SonarQube for static analysis. However, we don't see the test coverage reported in SonarQube. But it lists the Groovy tests under Unit Tests section. In SonarQube…
Yohan Liyanage
  • 6,840
  • 3
  • 46
  • 63
8
votes
3 answers

How to mock a single method for a class in Spock?

I have a method like below in my class that I'm trying to test: class SomeHelper { ByteArrayOutputStream fooBar (Request request) { ByteArrayOutputStream baos = someParser.parseData(getRequestFileInputStream(request.filename)) …
Anthony
  • 33,838
  • 42
  • 169
  • 278
8
votes
2 answers

Preventing unsanctioned deploys in Jenkinsfile (Multibranch Pipeline)

We're running Jenkins with multibranch pipeline plugin attached to GitHub organization's repository with Jenkinsfile in some of its branches. Jenkins has access to multiple other agents & nodes where it deploys code after it's successfully…
Andrew Dunai
  • 3,061
  • 19
  • 27
8
votes
4 answers

How to dynamically pass credentialsId to Jenkins pipeline

Is there a way to dynamically pass the credentialsId in Jenkins pipeline within the withCredentials block using an environment variable? Currently this works: withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId:…
user3575337
  • 194
  • 1
  • 1
  • 8
8
votes
1 answer

Why do I need keyword `this` while using `env` or `param` in DSL closure in Jenkinsfile

I have code based on "structured DSL" concept. // vars/buildStuff.groovy def call(body) { def config = [:] body.resolveStrategy = Closure.DELEGATE_FIRST body.delegate = config body() node { assert env assert…
vartec
  • 131,205
  • 36
  • 218
  • 244