Thursday, July 2, 2009

(This is my second post in a series about FogBugzReporter, a small open source app that I originally wrote in Java and later ported to Groovy. See the first post for more information and for links to other posts in the series as I write them.)

When I first ported FogBugzReporter to Groovy, I was able to take advantage of a free 1 year license for JetBrains IntelliJ IDEA (version 7) and its nice Groovy support. I had good experiences with it, but when the year ran out, I was both reluctant to pay for a new license and curious to explore the Groovy and Grails support in NetBeans. At the same time, I was interested in trying out Apache Ivy for dependency management. As it turns out, Laurent Forêt wrote a plug-in for NetBeans called IvyBeans which integrates Ivy with the NetBeans internal build infrastructure. So, if you reference a library in your ivy.xml, not only is it downloaded into your local repository (located in %USERPROFILE%/.netbeans/<netbeans_version>/modules/ext/cache on Windows) but it's also added as a NetBeans project dependency. This post describes what it was like to move to NetBeans and start using Ivy.

Although I'd previously used NetBeans 6.1 and 6.5 for some small Grails apps, by the time I got around to moving FogBugzReporter into NetBeans, the 6.7 release process had already reached Milestone 2 or 3 (it has since been released!). Since the Groovy/Grails plug-in for 6.7 provided better, more up-to-date support, I decided to jump directly to it. After installing the base version and adding the Groovy/Grails plug-in, I looked over the options for opening the project in NetBeans. I couldn't see any easy way to either import the project based on the existing IntelliJ files or create a new project pointing to the existing sources (any suggestions?), so I ended up doing something weird along the lines of creating a new project and checking out the files from Subversion on top of it. I don't remember the exact steps, but even if I did I might not repeat them here, since I'm sure there's a better way to do it. Once that was done, I was a bit disappointed to discover that I was unable to designate my Groovy script (MainFrame.groovy) as the project's main class. This was even true after I converted the script into a class and gave it a main method. Fortunately, it's still possible to run the app inside NetBeans by selecting that file and choosing Run File (Shift+F6) from the Run menu.

Next, it was time to try out Ivy and IvyBeans. At the time, there was no up-to-date build available, so I built from HEAD, but at this point you can just download 1.1 Milestone 3. Installation is as simple as extracting the zip you just downloaded and then following the basic plug-in install steps. I searched on MVNRepository.com to find the appropriate org (a.k.a. group) and name for each of the two libraries my project uses. I then removed the libraries from the NetBeans project, temporarily making the IDE unhappy. After I added lines of the following form to ivy.xml and then executed a Clean and Build on the project, Ivy downloaded the libraries, IvyBeans made them available to the project, and the build completed successfully. Pretty cool!

My transition to NetBeans isn't totally finished, but it's almost there. One thing I still need to figure out is what changes are needed to allow me to run an external build using the ant build.xml file generated by NetBeans – I think it involves specifying a few properties that are currently absent when ant is run standalone.

As I've said in most of my posts, please tell if you know of a better way to do any of what I've described above. I'm definitely not an expert in NetBeans or Ivy.