Groovy – unable to resolve class

The Problem

I have a groovy script that I’m writing and I’m trying to [link to | include | reference] another groovy “library” that I’ve [written | downloaded].

I import the “library” at the top of my script:

import com.mycompany.SomeGroovyLib

But, when trying to run my script, it fails with an error:

W:\path_to_file\script.groovy: 9: unable to resolve class com.mycompany.SomeGroovyLib
 @ line 9, column 1.
   import com.mycompany.SomeGroovyLib


I’m using IntelliJ IDEA 2017.2.6 on Windows with groovy 2.4.6 but the same happens on earlier versions.

The solution

This is a simple one.

From the “File” menu [1], choose the “Project Structure…” menu item [2]:


Then, from the “Project Structure” dialog, choose the “Modules” item in the left pane [1], then the “Dependencies” tab [2]. Now choose the + symbol on the right hand side of the dialog [3] and choose the “1 JARs or directories…” option [4].


Now, navigate to the path of your groovy library such that the path of your import statement …:


…can be found immediately within the folder you select:


Finally, you will be prompted to choose what type of thing you’re linking to and you should select “Classes”:


Now you can “ok” your way back through the 2 dialogs and your project should build.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s