creating a groovy project with gradle in eclipse

Last month, I went to a talk on gradle.  Today I decided to give it a shot.  My goal was to create a simple groovy project with gradle.  I did it in less than 30 minutes so getting started was fast.

Setup

I already had the Groovy Eclipse plugin.  I then installed the Gradle plugin from the Eclipse marketplace.  Yes, this could be done at the command line.  I’m used to M2Eclipse IDE integration so wanted the same for Gradle.  This step went as smoothly as any other plugin.

Creating a new gradle project

Just like Maven, the first step is to create a new Gradle project.  Since Groovy Quickstart wasn’t in the list, I choose Java quickstart.   The create request appeared to hang, being at 0% for over five minutes.  This was the first (and really only) problem.  I killed Eclipse and started over.  There was no point in doing that.  It just takes long. Apparently, this is a known issue. I tried again and after 5 minutes Gradle did download dependencies from the maven repository.

Making the Java project a Groovy project

Java quickstart does exactly what it sounds like.  It creates a project using the “Maven way” directory structure for Java.  To adapt this to a Groovy project, I:

  1. hand edited build.gradle to add
    apply plugin: 'groovy'
  2. hand edited build.gradle dependencies section to add
    groovy group: 'org.codehaus.groovy', name: 'groovy', version: '1.7.10'

    (I actually missed this step on the first try and got the error “error “you must assign a Groovy library to the ‘groovy’ configuration”.  The code was documented here.)

  3. created src/main/groovy and src/test/groovy directories
  4. gradle > refresh source folders.  This is like Maven where you need to refresh dependencies and the like to sync the Eclipse workspace.
  5. gradle > build > click build (compile and test)

Impressions of the gradle plugin

  1. I’ve mentioned a few times that it is very similar to the Maven plugin.  This is great as the motions feel very familiar and only the part that is new is gradle itself.  (Well that and refreshing my groovy knowledge – it’s been a while.)
  2. You can run your GroovyTestCase classes through Eclipse without Gradle (via run as junit test)
  3. My first build (with one class and one test class) including some downloading the internet took 1 minute and 2 seconds.  My second build took literally two seconds.
  4. I like the “up to date check” so only some targets get run.
  5. I like that you get an Eclipse pop-up if any unit tests fail.
 
This blog post also motivated me to start using my github account to make it easy to show the code.  In particular, the build.gradle file or the whole project. (This class doesn't require any programming so I think it is ok to put this online.  If Coursera complains, I will take it down.)

trying architexa – an eclipse diagramming plugin

Architexa recently announced free licensing for individuals or teams of up to three.  I figured I’d run it against CodeRanch JForum to see what happens.

Requirements/Install

The software is an Eclipse plugin.  You get the link after registering.  A different update site is provided for Eclipse 3.X vs Juno (4.2).  I know some CodeRanch JForum developers use IntelliJ IDEA.  I don’t, so I can try it out.  The install was smooth.  I did get asked to confirm I trust the certificate within Eclipse.

One minor discrepancy.  The website says the software is free for individuals and teams of up to three developers.  The email confirming your email and welcoming you says the software is free for individuals and teams of up to four developers.  Moot point at the moment since I’m using it as an individual.  But Architexa should sync these up.

The email asks me to validate my email using a localhost link.  Same for editing my profile.  I can’t click on it to validate.  Hm.. I then went to the website and clicked the “forgot password” link.  This got an emailed password which I could use to validate in Eclipse itself.  Again the change password link is a localhost link.  After entering that password, Eclipse said my account was validated.  So while the links are broken, I’m in the tool.

Learning curve

Architexa asks which projects it should index.  I said just JForum.  Architexa provides good Eclipse “cheat sheets” to start out quickly.

Layered Diagram

This is like a dependency graph for packages.  Very nice.  If you mouse over, you see incoming (afferent) and outgoing (efferent) dependencies.  You can also drill down to see lower level packages.

Class Diagram

Right clicking a package opens the option to create a class diagram.  Two classes generated on top of each other, but I can drag them around (or highlight them or call other attention.)  It is easy to view the source code from the class diagram.  I don’t see how to view the method names/fields in the class diagram.  This info is available in the outline view in Eclipse already though so it isn’t critical.

Sequence Diagram

This appears to be an enhanced editor.  You drag classes into it and it shows calls.  This seems like more work to create.  I tried dragging a few items over and “add all” to get the calls.  Unfortunately calls aren’t so much within one or two classes so this didn’t help much.  I didn’t create anything worth taking a screenshot of.

Overall opinion

The package diagram caught my attention the most.  I really like the dependency arrows.  The class diagram provides a nice visualization as well.  The sequence diagram seems like it would be a good documentation aid if one was creating sequence diagrams for the project.  Which I’m not because we inherited the design of the code and I’m already familiar with the flow.  I think more value would come from sharing documents and using the tool as a team.

For a “real” (paid) project, I”m not sure I’d be so thrilled to keep my documentation in a proprietary tool. Even a free one.  But for getting a feel for the software on a product that is “documentation-lite” or “no documentation”, the layered (package) diagrams and class diagrams provide a nice way to jump in.  Assuming you are using Eclipse already of course.

Eclipse Memory Analyzer

Last time CodeRanch has a memory leak, a teammate ran Eclipse Memory Analyzer and I ran JVisual VM.  This time, I did both.  I took the heap dump as described here.  JVisual VM told me hibernate was using a ton of memory.

To run

To run Eclipse Memory Analyzer, I needed to launch Eclipse with more memory.  The default wasn’t enough to open the heap dump.  On Windows, I would edit the eclipse.ini file.  On Mac, I instead used a command line.  (I have read that it is supposed to be possible to edit the eclipse.ini too.  Didn’t work the once I tried it.)

./eclipse -vmargs -Xmx4g -XX:-UseGCOverheadLimit

(It was a production dump; just under 1 GB.)

What I learned

The Leak Suspects report was right on. It noted that the heap dump had three large Hibernate Session objects.  I was only expecting one.  We are using Entity Factory (which use Hibernate Session behind the scenes if using Hibernate JPA).  It turned out there was some code which intended to to cache the entity factory, but in fact didn’t for some nightly jobs we have.