Intellij IDEA not importing dependencies from @Grab in Groovy project
Asked Answered
M

2

46

I have a groovy script I am working on, which imports dependencies using the @Grab annotation. This script will run within IDEA, and from the command line. However, within the IDE, the imports are shown in red (as unresolvable), and no auto-completion on the classes so imported is given.

I am accessing a corporate repository via a proxy, which has been configured as the Http Proxy within IDEA (the module should be, and is, in my local .m2 repo anyway!)

Anyone got any ideas (no pun intended!)?

I am using IntelliJ IDEA 12.5 Ultimate (IU-129.1135), JRE 1.7, and Groovy 2.1.6

Mousterian answered 26/8, 2013 at 15:15 Comment(2)
Alt+Enter on the annotation to fetch the dependency.Dharana
MAybe its the same as #18464954Principal
L
82

As stated by CrazyCoder, Alt + Enter then select Grab the artifacts and Enter

Logwood answered 30/8, 2013 at 14:56 Comment(3)
Thanks for that. Sorry I was not monitoring SO in a while.Mousterian
They need better integration. They already understand @Grab, just need to auto import like MavenLyda
I have also noticed, you need to have the ivy JAR files added as a module library for the Groovy script.Mousterian
F
5

There could be 2 problems interfering with the resolution of the Grab dependencies

  1. Your source code folder has not been marked as "Sources Root". To do that, right click on the folder and select "Mark Directory As" -> "Sources Root"
  2. Your project does not have a valid Project JDK. To do this, hit Ctrl-Alt-Shift-S, select "Project" -> "Project SDK" and give it a Java JDK.

Once these steps are done, you should be able to hit Alt + Enter and then select "Grab the artifacts"

Fuegian answered 5/7, 2016 at 10:7 Comment(2)
Thank you! Marking the directory as «Sources root» has helped.Wadmal
I had to give the project a Java SDK in order for the menu context item to appear, thanks!Bert

© 2022 - 2024 — McMap. All rights reserved.