DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Coding
  3. Languages
  4. Statically Compiled Groovy: Give Groovy a Chance

Statically Compiled Groovy: Give Groovy a Chance

Give Groovy a chance.

Tucker Pelletier user avatar by
Tucker Pelletier
·
Mar. 27, 19 · Opinion
Like (6)
Save
Tweet
Share
14.40K Views

Join the DZone community and get the full member experience.

Join For Free

One of the biggest complaints I hear about Groovy is that it is a dynamically compiled language — not that any dynamic language or platform could ever become popular or useful (Python, JS/node, Ruby, and more). However, Groovy isn't just a dynamic language; it's an optionally typed language. This means you can mix and match the power of a dynamic language with that of a statically compiled language.

Another complaint I often hear once people realize that Groovy can be statically compiled using an annotation at the class or method level is that it feels bolted on. To address the second concern, I recently released a Gradle plugin called Enterprise Groovy, which can be found on my GitHub page.

Enterprise Groovy gives you static compilation by default, which provides optional enforcement through a configuration. This provides options for disabling dynamic compilation, which can also be done by an annotation, disallowing def in most places and restricting which compile static extensions can be used. Enterprise Groovy is meant to be used for projects where you want to rein in the dynamic features because you have a big team or junior developers, and you don't want them to be able to write bad code with dynamic features (even though you can write bad code in any language).

Image title

Enterprise Groovy also provides you with a task for the Groovy console, which is run in the context of your project. The Groovy console can is a very helpful tool because it allows you to play with Groovy code and run it in context. The Groovy Console also comes with an AST(Abstract Syntax Tree) Browser, which allows you to look at the code at different stages of the compilation process. While that might not seem useful to the normal user, it gives you valuable insight into what the compiler does to your code. For example, if you use Groovy's @ToString annotation, this is actually an AST Transform, which adds an implementation of a toString method to your code during compilation. With the AST Browser, you can see what that implementation will be, which takes away the magic of Groovy and just makes it like any other tool.

So, why would you want to use Groovy in the first place?

  • Actively being updated (it may be faster than you remember with additional features)
  • Very nice and has a helpful community
  • Runs on the JVM
  • Contains seamless interop with Java
  • Holds optional static compilation/type checking
  • Less verbose than Java due to Inline Lists/Maps, Triple-quoted strings, etc.
  • Functional, with aspects and closures delegates
  • Runtime metaprogramming
  • DSLs to simplify problems (Spock, Geb, Gradle, Grails, etc.)
  • Compile-time metaprogramming (AST transforms/Macros)
  • Macro Methods
  • Enhanced JDK (Extension Methods)
  • Enhancements for scripting

That's not all — Groovy has a lot of other powerful features. I like to use the analogy that it's like a forge; you have the power to forge code and do what you want with dynamic features like metaprogramming, both at runtime or at compile-time, which lends itself to be useful for creating DSLs (Spock, Geb, Gradle, Grails, etc.).

In fact, Enterprise Groovy uses the compile-time metaprogramming with an AST transform to give you the power to control some of Groovy's dynamic features and have Groovy statically compiled by default. Groovy can also be used with many popular frameworks Spring/Spring Boot, Micronaut, Ratpack, Grails, and others.

Groovy has been more or less the silent contender of the JVM languages that gets less attention than some of the other JVM languages like Kotlin or Scala. That's been one of its biggest problems. While the community is nice, it doesn't have much excitement in terms of marketing. Despite this, many people continue to use Groovy to get stuff done, which is apparent, as Groovy was downloaded over 100 million times last year. OCI has been a big contributor to Groovy, taking over where Pivotal left off, helping release Groovy 2.5 and making it work with Java 9+, adding macros/macro methods and some updates to AST transforms. OCI and the community have also been working on Groovy 3, which should come out sometime this year with aditional improvements.

So, with all that being said, I think it's time to give Groovy a chance, if you haven't already. Here is a link to a bunch of other Groovy resources to get you started.

And have a Groovy one!

Groovy (programming language)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • DevOps vs Agile: Which Approach Will Win the Battle for Efficiency?
  • Running Databases on Kubernetes
  • How To Use Linux Containers
  • How To Handle Secrets in Docker

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: