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

Jenkins EnvInject plugin + Pipeline job

I would like to use EnvInject plugin within my pipeline job. So, I have a possibility to set checkbox "Prepare an environment for the run", but there is no action "Inject environment variables", like in freestyle job. I declared my variables in…
Sviatlana
  • 1,728
  • 6
  • 27
  • 55
8
votes
3 answers

why can quotes be left out in names of gradle tasks

I don't understand why we don't need to add quotes to the name of gradle task when we declare it like: task hello (type : DefaultTask) { } I've tried in a groovy project and found that it's illegal, how gradle makes it works. And I don't understand…
Zijian
  • 207
  • 1
  • 9
8
votes
3 answers

spock - mock static method is not working

I am trying to mock the one of static method readAttributes using groovy's metaClass convention, but the real method get invoked. This is how I mocked the static function: def "test"() { File file = fold.newFile('file.txt') …
8
votes
1 answer

How to mock methods/functions provided by Traits in Groovy

Here's an example: trait Sender { def send(String msg){ // do something } } class Service implements Sender { def myMethod1(){ send('Foo') myMethod2() } def myMethod2(){ } } I am trying to test…
bytekast
  • 81
  • 3
8
votes
3 answers

Logback.groovy LogstashEncoder altering field names

I have a logback.groovy that sends data to a logstash on the network with some custom fields: appender("LOGSTASH", LogstashTcpSocketAppender) { encoder(LogstashEncoder) { customFields = """{ "token": "xxxxx", "environment":"dev",…
Eric Darchis
  • 24,537
  • 4
  • 28
  • 49
8
votes
2 answers

Groovy: strings with embedded quotes don't execute as expected

This is weird: using groovy strings to hold some command lines for execution, I find that sometimes if there are quote characters inside the string, the execution simply silently fails. WTF? (Updated, see below.) Here's my test program: print " 1:…
Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
8
votes
8 answers

Convert datetime in to date

How do I convert a datetime field in Grails to just date, with out capturing the time? I need to do this for comparison with system date. class Trip { String name String city Date startDate Date endDate String purpose …
Omnipotent
  • 27,619
  • 12
  • 30
  • 34
8
votes
4 answers

Do grails domain classes have to be tied to a database?

I am a complete noob when it comes to grails (and still very noobish when it comes to groovy) so I apologise if this is a dumb question. I am building a simple web app and I want to control portions of the domain in my app based on file system…
Michael Rutherfurd
  • 13,815
  • 5
  • 29
  • 40
8
votes
1 answer

How can I add classes built previously in compileJava task to the current tasks classpath

Basically what I've got is a few steps involving a 3rd party compiler. Compile the Java classes. Transform some xls files to drl's. Call drools package builder and build the last file with all previously built files in the class path. If I call…
user447607
  • 5,149
  • 13
  • 33
  • 55
8
votes
1 answer

Accessing file resources in SoapUI Mock Service Deployed in tomcat

Problem in short : Accessing local file in SCRIPT Dispatcher with respect to project path i.e., def file = new File(groovyUtils.projectPath+"/${responseFileName}.xml"). This is working fine when the test is run from SoapUI as Mock Service. But…
Rao
  • 20,781
  • 11
  • 57
  • 77
8
votes
3 answers

Grails 3 @Delegate notation, using a domain object

Under Grails 2.4.4, we had classes we used as wrappers for domain objects. They would look like this: class Foo { @Delegate OurDomainClass ourDomainClass ... } This worked, but when trying to compile under Grails 3.0.11, we get this: >…
Sean LeBlanc
  • 185
  • 2
  • 12
8
votes
1 answer

Groovy: this.metaClass Versus instance.metaClass

I have encountered below groovy script code in the book . And it generated some strange outputs to me. class Person{ def work(){ println "work()" } def sports=['basketball','football','voleyball'] def methodMissing(String name, args){ …
Guocheng
  • 543
  • 3
  • 15
8
votes
2 answers

Gradle rule-based model nested beans syntax

I want to try new rule based configuration in Gradle to configure my plugin. Plugin's purspose is uploading data to cloud storages, like Google Drive or S3. I need a configuration for each storage the user want's to use. So, what I want to achieve…
madhead
  • 31,729
  • 16
  • 153
  • 201
8
votes
2 answers

In groovy [].sum() returns null when I expect 0

In groovy [].sum() returns null when I expect 0
Peter
  • 5,793
  • 4
  • 27
  • 31
8
votes
5 answers

Access the request XML in a SOAP UI mock response script

I have a mock response, which needs to return a value that was in the request. For example, this request can come in: 123 I already have a…
Jonathan
  • 191
  • 2
  • 3
  • 8
1 2 3
99
100