How to configure new Groovy SDK

Answered

I am using IntelliJ 11.1.3 and there doesn't seem to be any intuitive way to configure a new Groovy SDK. So let's say I download a new version of Groovy and want to create an SDK so I can assign it to my project. How do I do this?

There also seems to be a huge usuability issue with adding a Groovy SDK to an exising project. For example, if I want to add Groovy support to an exising java project. There doesn't seem any intuitive way to do this.

The only way I found to add groovy to an existing project is to create a new File then give it a .groovy extension. At that point IntelliJ does helpfully offer to configure a SDK (with the option to create a new one with a different version). How could I add the SDK without having to give a file the .groovy extension though?

I would think going to Project Structure->SDK's would be it. But that only offers to create Java, Android, or IntelliJ SDK's. Likewise Global Libraries only offers Java and JavaScript libraries. Creating a Groovy library there doesn't give the ability to create Groovy Scripts/Classes via the New menu (right-click context menu)

The whole adding Groovy SDK's and adding Groovy to an existing project really needs some usability work.

19 comments
Comment actions Permalink

Hi Michael,

I accept your feedback. Thank you!

To add Groovy support to a module open 'Project' toolwindow, invoke context menu on the module, and click 'Add framework support...'

--
Max Medvedev
JetBrains, Inc

"Develop with pleasure!"

1
Comment actions Permalink

Thanks for that pointer! That is quite helpful.

IMHO, you should be able to configure a new Groovy SDK in the same place I add a Java SDK. That seems to be the most intuitive place, at least to me, to look for it.

2
Comment actions Permalink

And what is the way to change the groovy SDK version for the project once it has been set?

0
Comment actions Permalink

Add your new Groovy version as a global library

File->Project Structure->Global Libraries,

Then on the modules section of Project Structure click the dependency tab, then add the global library as a dependency (and remove the previous one). Click the + sign then Library->Global Library.

 

 

1
Comment actions Permalink

I have really no Idea how to change Groovy SDK on existing project.... 

0
Comment actions Permalink

Remove the existing Groovy library you have now in the module dependencies and in the global libraries, then add a new library:

2
Comment actions Permalink

Thank you :)

Is there a way to change groovy compiler ?

1
Comment actions Permalink

This is not working at all, I found 3 different ways to add Groovy SDK
and it still keeps ignoring it. 
I have under "Global Libraries" a "groovy-2.4.13" and if I add under
"Modules" a Framework "Groovy" the dropdown list is empty, showing
"No library selected". If I use the "Create" button and re-add the SDK,
it will be displayed under "Dependencies" but still the dropdown list is empty,
the "Build" says "Cannot compile GRoovy files: no Groovy library is defined"...
Even using the Hint "Configure Groovy SDK..." shows again an empty
dropdown list, and using Create has absolutley no effect at all.
I feel IntellJ has a lot of bugs, especially with Groovy, also with Cucumber but
that's another chapter. Every IDE can do Java, you should be able to do more
with such a pricey product!

 

0
Comment actions Permalink

Please submit a ticket via https://intellij-support.jetbrains.com/hc/requests/new and attach a sample project to reproduce this issue.

0
Comment actions Permalink

In 2018.3 there is no Groovy Framework to select (on an existing groovy project). There is also no global library option for Groovy.

 

0
Comment actions Permalink

You probably already have Groovy library in the module dependencies, please double check: https://www.jetbrains.com/help/idea/creating-and-managing-modules.html#working-with-module-dependencies.

0
Comment actions Permalink

Indeed I do, but this subject is about changing the Groovy version. To do it you need to add a *java* library for the new Groovy version i.e.

  1. File -> Project Structure -> Global Libraries -> + Java
  2. Point it at ~/.sdkman/candidates/groovy/2.5.6
  3. *then add* ~/.sdkman/candidates/groovy/2.5.6/lib to that library using the + at the top (this makes it understand this is Groovy) because it doesn't auto import the classes
  4. -> OK
  5. back in to Project Structure -> Modules
  6. Remove old groovy-2.4.x and add Library groovy-2.5.6
  7. -> OK
  8. *Close and re-open IDE*

Simple really ;-)

0
Comment actions Permalink

Removing the existing library and adding a new one via the framework support like described in the previous answer seems to be a bit easier than what you suggest:

https://intellij-support.jetbrains.com/hc/en-us/community/posts/206224119/comments/360000152759

0
Comment actions Permalink

You mean the UI is: remove the module dependency on groovy so you get the option of adding framework support for groovy where you can then add a new library at which point it removes the add framework support option? I, and it seems others above, would never have guessed that as a workflow. We don't want to remove framework support for Groovy, we want to change the version of Groovy.

0
Comment actions Permalink

This is still an issue and the mechanics are so flawed. If I get the option in a dialog about a non-configured groovy to set a library that contains groovy, why is it not accepting my selection. This issue is no 7 years old and still exists. Usability is zero on this, I even had to restart my IDE... in 2019, Ultimate indeed -.-

0
Comment actions Permalink

Alex, this thread is about changing the version of the existing library, not adding a missing library. If you have issues with that, please file a bug at https://youtrack.jetbrains.com/issues/IDEA and provide the steps to reproduce the problem, attach a sample project.

0
Comment actions Permalink

I concur with the frustration expressed by many above having landed here after spending more than an hour trying to add a Groovy test class to a Java project - IntelliJ config usability is very poor indeed imho.

1
Comment actions Permalink

The process of these operations is indeed cumbersome and not intuitive enough.

However, in the search engine can quickly find this post and solve the problem, this is still good.

0
Comment actions Permalink

I agree this issue is pretty ridiculous considering it was first reported 11 years ago and is still mystifying users. Even after reading this entire thread I still couldn't figure out how to get IntelliJ to let me add groovy as an external lib. Finally I looked at the config files in another project where it was already working properly and found a way to do it. So, without further ado, the easiest way I've found to add/change groovy in my projects is to drop a new config file into the .idea/libraries folder, such as this one:

Filename: groovy_3_0_9.xml

<component name="libraryTable">
<library name="groovy-3.0.9" type="groovy-library">
<properties version="3.0.9" />
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/groovy-bsf-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-jaxb-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-dateutil-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-datetime-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-cli-commons-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-ant-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-jmx-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-groovydoc-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-json-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-docgenerator-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-jsr223-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-servlet-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-nio-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-testng-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-sql-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-templates-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-macro-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-yaml-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-cli-picocli-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-astbuilder-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-test-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-test-junit5-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-xml-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-swing-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-groovysh-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-console-3.0.9.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-3.0.9.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/lib/groovy-ant-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-astbuilder-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-bsf-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-cli-commons-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-cli-picocli-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-datetime-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-dateutil-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-jaxb-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-docgenerator-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-jmx-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-jsr223-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-groovydoc-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-console-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-macro-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-nio-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-servlet-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-json-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-groovysh-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-sql-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-templates-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-test-junit5-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-testng-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-yaml-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-test-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-swing-3.0.9-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/groovy-xml-3.0.9-sources.jar!/" />
</SOURCES>
</library>
</component>

Then open your project structure settings, (File-->Project Structure), click the Libraries tab and you should see your missing groovy lib listed there in red. Click on it and then select "change version". It should list the available groovy versions. If your version is not already selected, select it, then click "ok". It will download the libs to your $PROJECT_DIR/lib/ directory and you should be good to go. 

0

Please sign in to leave a comment.