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.
Try "BUSL"
2022-10-26 NOTE: HISTORIC. "BUSL" seems to be dead. Last archived webpage is from 2020.
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.
Try npm-groovy-lint
You can use npm-groovy-lint
via command line with --format
option :)
spidasoftware/format extracts the groovy eclipse plugin and provides a command line interface to it.
Instructions:
git clone [email protected]:spidasoftware/format.git && \
cd format/bin && \
./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:
Older groovyc had some formatter
2022-10-26 NOTE: HISTORIC. The formatter seems to have disappeared in newer versions. See comment.
Actually groovyc
came 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!
Spotless also formats groovy. Seems to be impossible to run without gradle/maven though. :(
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.
© 2022 - 2024 — McMap. All rights reserved.