Lightweight Groovy IDE mode for script editing?

When groovy is installed on a machine you can launch groovy scripts through double click on Windows or even like shell scripts on UNIX. Since my department is very Java-centric we've been starting to use groovy instead of bash/perl/python scripts to do small tasks. It would be nice to be able to use IDEA effectively on such files.

I can get a really lightweight editor for groovy by dragging groovy script into IDEA, on whatever project I happen to be open. This gets me a syntax-aware editor, but it works horribly because everything is highlighted in red as IDEA does not even recognize the standard Groovy classes, and because of this of course there is no auto-complete. This happens even if I drag open the file in a project window that is using Groovy.

My current solution if I need to make a big change is to create a blank Maven project/POM referencing groovy jar. Then I copy scripts into that project, edit, then copy them back to the desired location. This works, but is annoying because I'm manually "syncing" files around. Or, if I make a small change I just use text editor like VIM, but IDEA is much better than VIM.

Scripts can be found anywhere on the file system, I don't want to have to setup a whole IDEA project just to edit one small groovy script. Is there a better solution that fits these requirements:

  1. Edit in an ad-hoc manner groovy script/class files not in a project/coding setting?
  2. No need to create a project -- I don't want .idea folders scattered all around my disk.
  3. I don't care to compile the groovy files
  4. Still support the groovy feature when A.groovy and B.groovy are in the same directory, A can reference B ("groovy classpath"). If this means IDEA opening all *.groovy in a directory, that's good.

I'm OK with any solution that requires one-time setup like installing groovy in some place and/or selecting "default" groovy jars to reference from IDEA, etc.


I found this old message from 2009:

I didn't think about it, but I can create the blank project then add the directory where the scripts are as new content roots so I don't need to create new projects each time. However, if you have two groovy files of the same name, even though they are in two different content roots and would work with groovy on command line (because they are in different directories), IDEA will get confused because it mashes the classpaths together. I suppose the workaround in this case is to create a new module, but that requires a lot more setup than adding a content root.

Since that post, is there any improved way to work with Groovy scripts?


IDEA 11 has Groovy Shell (Tools menu). It's a more light-weight method of working with Groovy scripts. Please try it and report if it satisfies you


Yes I am familar with groovy shell and it is excellent for ad-hoc commands and interacting with current classpath. One of the things I've always really liked about dynamic languages like groovy and python is the ability for quick experimentation from command line/interactive prompt, and groovy shell in IDEA brings that power to Java projects as well in a way that's easier than compiling/running a small main.

But I am talking about scripts that I would run outside of IDE, for example where one might use .bat or .sh files and clicking to run them, but still be able to use the power of IDEA. For example, maybe a script to run a query on a database and display the result, or a script that takes a parameter from a Swing UI in addition to command line is nicer in Groovy than in shell scripting.

So far I've been using the "content root" trick to add content roots, so I keep IDEA project files out of non-coding/unrelated folders, and it's been working well enough for me.


Then I'm afraid we have nothing better so far, not even an idea what this could look like. If you have one, feel free to file a feature request to our tracker, thanks.


To be honest, once I realized I could use content roots, it is working well enough for me for the rare times I do edit the scripts. There is the problem with conflicting names, but in practice I've not named 2 classes the same yet.

I understand there has to be a project of some sort to have a classpath set up, so it's hard to get the power of IDEA but the lightweight nature of something like VIM.

I would put this pretty close to the lowest priority of all IDEA wishes I've thought of, but in a dream world, IDEA could work this way:

  1. Ability to open groovy file with IDEA as a file association (for example right click "edit with IDEA")
  2. IDEA acts like it has opened a project, which is created from template settings project (like normal), and adds groovy dependency found at GROOVY_HOME (or if a global library/GDK setup like JDK setup is required, would also be equally fine) for autocomplete. But it does not save this project to disk. If project HAD to be on disk because of IDEA design it would be OK to live temporarily in .IntelliJIDEA/system directory.
  3. IDEA acts like the script's parent directory is the sources root (so other .groovy in same folder can be referenced).
  4. IDEA does not need to compile any groovy classes, it just edits/saves files
  5. When you right-click run groovy file, it runs it via "groovy Whatever.groovy" rather than as "java -cp out Whatever"

The above is pretty much a streamlined version of what I would do today, which is create a temporary project in a place I don't care about getting messy, add groovy facet, add some folder as content root, mark it as "sources", and run groovy script, but it has the overhead of needing to compile. If IDEA had to compile to temp project folder, I wouldn't complain, though. If you look at this a little bit more generically, there is nothing actually specific about Groovy here. The feature instead could be "right click on folder to create a temporary project here" then it auto-detects facts (like web, groovy, hibernate, etc.) -- but then this is pretty much the same thing as "new project" creation as it exists today.

I'll make a ticket if you think it is useful and JetBrains won't take it too seriously. I think the effort would outweigh the value on this one, there a more important areas to improve in IDEA.


Please do file a ticket. Actually, we do have 'open directory' functionality in smaller IDEs like PHPStorm or PyCharm. So adding it to IDEA shouldn't be very hard. Harder is to figure out which JDK and Groovy SDK to use, not forget that this requires indexing, and somehow teach the project not to save and live without compilation.