JavaOne – Improve your Groovy Kung-Fu

“Improve your Groovy Kung-Fu”

Speaker: Dierk Koenig

For more blog posts from JavaOne, see the table of contents


Use cases

  • Spock for testing
  • System automation – Docker
  • Jenkins scripting console and pipelines

Recommends Groovy ref card

Groovy idioms

“a” == “b” – check if two strings are equal

a in col – check if element in a collection

${‘0’*10} – print 10 times

use Collections, {
time.shufle()
}

type .xyz vs .getXyz()

use “it” (default) instead of creating a variable for grep

catch(all) – vs catch(Exception e)

gpars dataflows – specify what want to do in tasks, but not the order [I had trouble following this part]

@Grab(“groupid:artifactid:version”) – get dependency from Maven Central. Can specify a resolver as first parameter if want to use an alternate one. Not worth it though because then as much work as setting up a project.

Command line

  • groovy -e “print 1” – command line eval
  • groovyconsole – interactive UI

My take: I like that he showed code that he wrote and pointed out idioms. Seeing well written code is helpful for seeing good practices. I also realized that I know more than I thought. Many of the items in this post I knew existed but aspire to use more. Or things I do and would like more of the team to do.

Leave a Reply

Your email address will not be published.