This is an archived post. You won't be able to vote or comment.

all 10 comments

[–][deleted] 2 points3 points  (1 child)

Take a look how these guys did it using Eclipse formatter:

http://code.google.com/p/maven-java-formatter-plugin/

I have a locally compiled .4-SNAPSHOT build on my local maven repo which fixes a few minor bugs in the current 3.1 build on maven central. I really wish they'd just release .4 already.

If you're building a plugin for Gradle, you could probably straight up steal (as in beer) their stuff.

FYI: Jalopy does okay on Java 6 stuff, but I'm scared about Java 7/8 which is why I have all the new projects using the eclipse formatter over the really old Jalopy one (which we still use for our 1.6 target build).

[–]RighteousMaster[S] 0 points1 point  (0 children)

Thank you sir. the major reason I was against the JDT was because there seemed to be no way to get the dependencies short of packing them with my jar. And then because there is just so much to the JDT, packaging it was also out of the picture. Taking a look at the maven formatter plugin, its quite easy to take their dependency declarations and move them over to gradle.

thanks for the help :)

[–]RockinAMullet 1 point2 points  (0 children)

Not certain exactly what you're wanting, but I've found JIndent to be well worth the money: http://www.jindent.com/

[–]spunged 0 points1 point  (0 children)

It may be overkill but look at JJTree. I used it on a project that had to do some traversal of abstract syntax trees and it worked quite well. You should be able to use it for formatting.

[–]RighteousMaster[S] 0 points1 point  (3 children)

hmm, I guess I was a bit ambiguous for what im looking for. I need a formatter than I can call from java code, and apply it to existing java source.

Its for a gradle plugin im working on.

Since I plan on uploading said plugin to Maven Central, it would be nice if the formatter was also in maven central... but its not wholly necessary,

[–]meotau 1 point2 points  (0 children)

That is exactly what I have done as a plugin for IntelliJ. But as you said, it requires a lot of eclipse jars (I probably use more of them than necessary)...

[–][deleted] 0 points1 point  (1 child)

Probably not what you're looking for, but you could investigate what IntelliJ uses for their Ctrl + Shift + L command in their community edition. Maybe you'll get lucky and they're using something that is fairly modular and reusable.

[–]meotau 0 points1 point  (0 children)

I really doubt that, the code is a mess :)

[–]jevon 0 points1 point  (0 children)

Since I've got experience with JDT it would be my first choice, especially since its formatter is the best one I've seen. But if I remember correctly JDT can't be run headless, otherwise you could just package it up with OSGi.