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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • How To Approach Dependency Management in Java [Video]
  • Retrieval Augmented Generation With Spring AI 2.0, Claude, and PGvector
  • Fix Circular Dependencies in PostgreSQL Row-Level Security With SECURITY DEFINER Functions
  • Sharing SBOMs Securely Without Giving Too Much Away

Trending

  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  • Choosing Voice AI Infrastructure: 7 Capabilities To Evaluate
  • The "Just Read the Code" Myth Is Killing Your AI Workflow
  • Android 4.4 KitKat, the Browser and the Chrome WebView

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Coding
  3. Languages
  4. Groovy Goodness: Download Grab Dependencies in IntelliJ IDEA

Groovy Goodness: Download Grab Dependencies in IntelliJ IDEA

The @Grab annotation is a useful one in Groovy, but did you know that you can make it even more helpful from within IntelliJ? Read on for the details.

By 
Hubert Klein Ikkink
·
Nov. 06, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

In our Groovy scripts, we can use the @Grab annotation. With this annotation, we define dependencies for our script and they will be automatically downloaded and added to the classpath when we run our script. When we use IntelliJ IDEA we can use a nice intention that is part of the IntelliJ IDEA Groovy support to download the dependencies from our IDE editor. IDEA downloads the dependencies and adds it to the project module dependencies. This is useful because this will also add code completion for the classes in the dependency to our editor.

Let's see this with a little example. We have the following Groovy script in our Groovy project in IntelliJ IDEA:

We place the cursor on the @Grab annotation and enable the intention popup using Alt+Enter (check Keymap Reference for the key combination). We select the option from the popup:

IntelliJ IDEA downloads the dependency. When we look at our Project Structure and at the Module Dependencies we see the downloaded dependency:

In our example, we added the Groovy script to a Groovy project in IntelliJ IDEA. When the project is a Gradle or Maven project we must make sure Ivy is part of the compile classpath because otherwise IntelliJ IDEA cannot download the dependencies using this intention. For example, we could add to a Gradle build file the following dependency compileOnly 'org.apache.ivy:ivy:2.4.0'.

Written with Groovy 2.4.12 and IntelliJ IDEA 2017.2.5.

intellij Dependency Groovy (programming language) Download Grab (software)

Published at DZone with permission of Hubert Klein Ikkink. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Approach Dependency Management in Java [Video]
  • Retrieval Augmented Generation With Spring AI 2.0, Claude, and PGvector
  • Fix Circular Dependencies in PostgreSQL Row-Level Security With SECURITY DEFINER Functions
  • Sharing SBOMs Securely Without Giving Too Much Away

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook