Tuesday, July 12, 2005

Java development without Ant

When Ant came out, I welcomed it. It was better than Makefiles for Java, it solved the path and classpath format difference between Windows and Linux, did not rely on shell programs. It did provide a platform independent way for building Java software. At that time, there was another alternative, JMK which had a lisp like syntax, and solved the same problems as Ant. But Ant was backed by apache, and this were the times of XML everywhere.
I got more and more fed up with ant scripts over the years. During a long time you had to resort to an XML trick just to include other ant file, you did not have conditionals, but more importantly, it is quite a pain to write long ant scripts in XML. XML is not that good to write logic with, XSLT did not become as big as it could have been partly for this reason.
Recently, Java IDEs (Eclipse) have made Java coding really comfortable, but why is it that for each project, you need to have to setup your project classpath, build, and write an ant script that does the same? In many companies I have seen ant scripts taking minutes to do a build in order to test your latest modification. This is crazy when it took a few seconds to eclipse to compile it, and it's already compiled, so why not using that output for testing your development? Ant, despite its codebase and age, does not do much: it does not calculate dependencies, it leaves that to the java compiler, it does not keep checksums of files to check if one has changed, it just uses file system dates (which can be a problem if you retrieve an older version of some file).
Now I am using a Jython script that justs copies my eclipse build and packages it appropriately, it works well, it is fast, it is flexible (all the power of python), and platform independent. You need to be a bit careful how you choose to design your Jython script, but hey, even with Ant limitations on messing everything around, I have seen so many awful Ant scripts.


Technorati tags:

8 comments :

  1. Hi.

    I agree with this opinion.

    I think that xml is not a good choice for script programming or even programming, and programming is what I see that the people who uses ant tries to do.

    I think "ant" can substitute something like unix makefiles, but building, promoting & checking sources and many other things in complex development team environments may require a serious programming.

    So, I'm sure that ?ython scripts are much better (more powerfull, readables and writables -and maybe you get better productivity-).

    But I think that languages like korn shell script are the best for building tasks (the best productivity) if you work on Unix development environment.

    Bye

    ReplyDelete
  2. I've also experimented with alternative build scripts, and went down the jython/python path as well. But in the end decided to go back to standard Make, which, despite a few issues detecting when java code actually needs to be compiled, seems to work pretty well. I guess if you've got cygwin installed, your makefile will (possibly?) be platform independent as well....

    ReplyDelete
  3. Have you tried taking a look at Maven? It is a great tool for java development. I have been using maven 1.0 instead of ant for the past year for all my projects and maven 2.0, which is still in alpha stage, promises even more features.
    Maven supports dependencies and there is a maven plugin for Eclipse known as Mevenide.

    ReplyDelete
  4. Hmm... I'm fine with Ant. As a matter of fact, I really like Ant. I also like XML and find it easy to work with. I really like to write build.xml files in Eclipse. Eclipse's Ant editor is great.

    Erik Weibust

    ReplyDelete
  5. There is a way to make Ant more acceptable, it is to code more specific tasks for your project in Java (or even Jython). That way you might be able to keep a clearly defined project structure in xml, while not using it for "programming". That would be very much like what James Duncan Davidson had in mind when he started Ant.

    But I still think a full Jython build system will in the end be more performant and more flexible. How to better express the structure than with jython code?

    ReplyDelete
  6. Fabian, Thanks for sharing the python script. it is really helpful anf much clean than ant crap....

    ReplyDelete
  7. You should definetely try buildr tool.

    I use it 2 weeks and I love it. Very extensible, very powerful.

    hhtp://buildr.rubyforge.org

    ReplyDelete