Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing build.xml with Build.java - using Java and the Ant libraries as a build system

I've grown disillusioned with Groovy based alternatives to Ant. AntBuilder doesn't work from within Eclipse, the Groovy plugin for Eclipse is disappointing, and Gradle just isn't ready yet.

The Ant documentation has a section titled "Using Ant Tasks Outside of Ant" which gives a teaser for how to use the Ant libraries from Java code. There's another example here:

http://www.mail-archive.com/[email protected]/msg16310.html

In theory it seems simple enough to replace build.xml with Build.java. The Ant documentation hints at some undocumented dependencies that I'll have to discover (undocumented from the point of view of using Ant from within Java).

Given the level of disappointment with Ant scripting, I wonder why this hasn't been done before. Perhaps it has and isn't a good build system.

Has anyone tried writing build files in Java using the Ant libraries?

like image 200
Dean Schulze Avatar asked Jun 09 '09 21:06

Dean Schulze


2 Answers

Our build system is primarily based upon exactly what you describe, and it works very well indeed. We use the Ant tasks (especially the file-manipulation tasks) from custom java programs which assemble the application using auto-discovery of convention-based application module layout.

You may need some glue Ant XML, to do things like compile the build scripts themselves, and to actually invoke the java to perform the build, but it's minor.

Not only is java more readable than Ant, especially when it comes to conditional execution, but it's vastly quicker. Our Ant-based build used to take a minute or so to assemble an EAR, now the java based version takes about 5 seconds.

like image 121
skaffman Avatar answered Nov 16 '22 02:11

skaffman


You had a fine idea. Cliff Click had a similar idea: http://blogs.azulsystems.com/cliff/2008/01/i-hate-makefile.html

If you go through with it I advise you to keep it as simple as possible so your build system doesn't need a [non-trivial] build system itself.

like image 24
Ron Avatar answered Nov 16 '22 01:11

Ron