Question

I use the commercial version of Jalopy for my Java projects but it doesn't work on Groovy files. IntelliJ has a serviceable formatter but I don't like requiring a particular IDE.

Was it helpful?

Solution

I've found that BUSL works really well on Groovy files. It's standalone too, so you can use it from your text editor or whatever.

OTHER TIPS

spidasoftware/format extracts the groovy eclipse plugin and provides a command line interface to it.

Instructions:

  1. git clone git@github.com:spidasoftware/format.git
  2. cd format/bin
  3. ./format /path/to/groovy/file

caveat: this project is no longer maintained however still works as of the time of this post

the latest eclipse plugin will do some formatting and refactoring: http://groovy.codehaus.org/Eclipse+Plugin+Refactoring

Groovy support for Jalopy is coming later this year. There is a tiny sneak preview on YouTube showcasing the Eclipse plug-in:

http://www.youtube.com/watch?v=PNFUzvOZei0

Actually groovyc comes with a builtin formatter (kind of). If you set the environment variable JAVA_OPTS to -Dantlr.ast and run groovyc test.groovy a file called test.groovy.pretty.groovy is generated.

But be aware: From what I found in the internet about this, this formatter is not configurable and strips comments!

I have yet to find a good solution for this, and I really wish that there was one. Regarding @Gizmomogwai's tip, it doesn't exactly work as you'd think.

First of all, you need to export JAVA_OPTS=-Dantlr.ast:groovy. However, the file produced by groovyc is clearly not "pretty" in the sense that it is pretty to humans. The "pretty" output generates a file which will be parsed by the next stage of the compiler. Effectively, this means that it not only strips comments but also will add and alter newlines and whitespace. It is definitely not suitable for checking code formatting.

Spotless also formats groovy. Seems to be impossible to run without gradle/maven though. :(

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top