The problem with Java building Java (hint: it's Java)
Marcus R. Breese
Posted: Feb 1, 2008
Updated: Mar 21, 2008
Source: Tim Boudreau's Blog: What if we built Java code with...Java?

I am very intrigued with the idea of new Java building infrastructure. I'm a pretty committed Ant devotee, owing to bad experiences with some early Maven builds. So far, there hasn't really been anything that I want to do that I can't get Ant to do. Every so often I needed to write a custom ant task, but that's pretty rare. However the main reason that I don't like Maven is that I'm a control freak. I like things in the directories that I want them. I don't like my project's build to the build tool. That just seems so counter-intuitive to me. But this post isn't about Maven...

Now, my needs are pretty simple: 1) setup directories, 2) compile classes, 3) run unit tests, 4) assemble jars/wars, 5) sometimes start/restart Tomcat. I don't deal with much inheritance simply because I don't need it. The few times I've tried, it ended up a giant sticky mess (that ultimately didn't work). My basic build directory setup is also pretty standard, so I can (for the most part) reuse a build.xml file from one project to another.

Even though Ant has served me well in the past, I have always had some uneasiness with the concept of using an XML "script". I've been slowly removing all XML configuration from my projects, opting instead for Annotations or DSL-style Java configuration (much like Guice). So, you could say that I've been in the market for an Ant replacement.

One top contender is Buildr. If you don't know, Buildr is a Ruby based build system for Java projects. (Such is the life of a polyglot). However, I've been holding off on trying Buildr until Ruby 1.9 comes out... I honestly don't have a good reason for not trying it...

Today I ended up reading about Gosling. Now this is an interesting idea that doesn't seem to be going anywhere (the last release was in January 2007). I starting to think about this a little more... why isn't there a Java based Java builder? I think this is a chicken and the egg problem. You need a builder to build the builder. And then it's even a little more complicated. You need a builder to build the builder so it can build your project.

Let's take a step back. What would the workflow look like for the developer? Well, if you're doing command-line builds (you can build all of your deliverables from a single command, right?) then you expect to be able to type a command and maybe an optional task. Such as: make all
Even if you're doing some nifty bootstrapping, you're still looking at something like: java -cp . Bootstrap Builder task
Now, if it were me I'd add a bash script to at least cover the java bootstrapping, so we're looking at something like build.sh task
That's a little better. But, you still have to compile your project's builder.

So now instead of having one set of source code, you have two. Your project, and your project's builder. And if your builder requires libraries, you have two sets of dependencies (at least... your unit test may have their own as well). But, once your builder is compiled, you can finally compile your project. java -cp builder/classes MyBuilder task
but that looks like crap (and takes too many keystrokes), so you'll have to write another shell/batch script. But at least we're getting somewhere.


This all seems very much like the saying "now you have two problems". I guess the point of this all is that while a Java based Java builder is an interesting idea, I'm not sure how much sense it makes. Look at the granddaddy of them all: make. Make exists largely to build C programs. Why not write a C builder in C? Well, then you'd have to first compile your builder...

(note to self: just try Buildr)