Home

News: Gosling: a build process that uses Java instead of XML

  1. Justin Lee has created the Gosling project on java.net. Gosling is a build processor similar to Ant except that instead of using XML for execution, it uses a Java source file. One interesting requirement is the use of 1.6 because of the compiler API. The name refers to the "Ugly Duckling" fairy tale instead of James Gosling. As an example of the compilation code, here's the default build task for Gosling to build itself:@Default @Description("Builds the Gosling project") public void build() { new Javac(this, BUILD_DIR) .addSources(new FileSet("src/java") .addInclude("**/*.java")) .addOption("-Xlint:unchecked") .addOption("-Xlint:deprecated") .addOption("-g") .execute(); new Copy(this) .setDestDir(new File(BUILD_DIR)) .addFileSet(new FileSet(JAVA_SRC_DIR) .addExclude("**/*.java")) .execute(); }What do you think of this approach to build scripts?

    Threaded Messages (35)

  2. I have been using ant and maven2 for building purpose in several j2ee projects. I think that the maven philosophy is better, and is not so important which language you use to write the build script file. Do they will use a "depedency" concept and a "3-rd party libraries repository" like maven does? Many other maven features are very useful and allow me to write very short build script files, thus it is not important to write them in XML or JAVA.
  3. It will leverage maven 2's repository for dependency management. I'm also hoping to be able to use eclipse's compiler instead of relying on 1.6's compiler API so that it's usable on 1.5 as well.
  4. re: compiler[ Go to top ]

    I'm also hoping to be able to use eclipse's compiler instead of relying on 1.6's compiler
    If you figure out how to do that could you post it here? I would like to do that for a project I'm working on but havent had time to research it.
  5. Re: re: compiler[ Go to top ]

    - Start 'javac' as external program (slow) - sun.tools.javac.Main (Sun JDK dependant) - Use e.g. Groovy which has support for compiling inside (different syntax but powerful) - Jikes, GCJ, ...
  6. Re: re: compiler[ Go to top ]

    - Start 'javac' as external program (slow)
    - sun.tools.javac.Main (Sun JDK dependant)
    - Use e.g. Groovy which has support for compiling inside (different syntax but powerful)
    - Jikes, GCJ, ...
    @see http://jcp.org/en/jsr/detail?id=199 @see http://jakarta.apache.org/commons/sandbox/jci/
  7. Thief[ Go to top ]

    Hi Justin, You stole that idea from me, but well done for actually implementing it. Three things: 1. Why annotations? 2. As a failover for 1.5 etc., you could simply invoke javac as an executable. 3. You could delegate through to Ant - nothing wrong with Ant's API, as far as I know. I'm getting my students to write their own Java editor - here's some sample code for calling out to javac from Java without using the undocumented APIs. It relies on javac being in the PATH, but that wouldn't have to be the case in Gosling - http://cime.net/~ricky/netsim/oldham/compile.html It's almost a shame this is written in Java, as the name Gosling invites duck typing jokes.
  8. Re: Thief[ Go to top ]

    1. Why annotations?
    What else would you recommend for things like target descriptions and defining the default and the like? XML? I'm not planning on having any XML involved at all.
    2. As a failover for 1.5 etc., you could simply invoke javac as an executable.
    I'm actually planning on either grabbing the compiler like ant does for those who don't use Sun's VM or compiler or using Eclipse's JDT Core to compile. I'll probably just use Sun's like ant does. Then those that want jikes can use it.
    3. You could delegate through to Ant - nothing wrong with Ant's API, as far as I know.
    Ant's API is pretty awkward to use and has some oddities because of the XML binding and the support for ancient VMs. I'd like to make this as clean a cut as possible while retaining at least some familiarity for experienced ant users.
    It's almost a shame this is written in Java, as the name Gosling invites duck typing jokes.
    Yeah. It was the first reasonable sounding name that was available that I thought of and couldn't think of any other name. Who knows? It might change later if something much better comes up.
  9. Re: Thief[ Go to top ]

    "What else [other than annotations] would you recommend for things like target descriptions and defining the default and the like?" I'm not sure I'd recommend this. There's a chance I'd consider it and then go your way, but: An interface, Project, that, among other things, specifies a List getTargets(), and a Target getDefault() Target would include a getDescription(). Etc. Tony Morris said, when prompted, that he would reconsider whether or not to use annotations on JTiger if he were rewriting it. I'm not sure of the merits of either approach. "I'd like to make this as clean a cut as possible while retaining at least some familiarity for experienced ant users." I expect you will, but as long as you make sure that your users can provide a hook to ant then you're ok. If you find out that they are, then you can include that hook in Gosling. Ant probably supports more compilers than Gosling ever will. Please, oh please, make it so that -jar and -cp can't get used together. Except with the IBM VM, where both can be used at once and meaningfully. The example that Mr. Ottinger posted looks reminds me of RIFE - http://rifers.org/09_stateful_counters/src/ParticipantSite.java for example
  10. Maven2?[ Go to top ]

    It will leverage maven 2's repository for dependency management.
    Is Maven2 usable yet? I tried it on a project at the end of last year/beginning of this year, and at that time it was utterly useless. From time to time it would start being unable to load classes present in jars in the repo, be completely unable to compile certain classes despite no errors in them etc etc..
  11. Maven 2[ Go to top ]

    It will leverage maven 2's repository for dependency management.


    Is Maven2 usable yet? I tried it on a project at the end of last year/beginning of this year, and at that time it was utterly useless.
    From time to time it would start being unable to load classes present in jars in the repo, be completely unable to compile certain classes despite no errors in them etc etc..
    Yes, but it's still not plain sailing. The most common problem I've come across is that http://www.ibiblio.org/maven2/ isn't updated with the latest library distributions and it's time consuming to manually install large frameworks such as hibernate or spring into your local repository. Also once you start getting a reasonably large project the dependencies make the POM of similar size to build.xml so I'm not sure the "small build script" argument is valid. Documentation hasn't kept up with the feature list but the support process works. Still some minor problems with class loading, but I haven't come across the specific problems you describe.
  12. Re: Maven2?[ Go to top ]

    It will leverage maven 2's repository for dependency management.


    Is Maven2 usable yet? I tried it on a project at the end of last year/beginning of this year, and at that time it was utterly useless.
    From time to time it would start being unable to load classes present in jars in the repo, be completely unable to compile certain classes despite no errors in them etc etc..
    I've been using it on most of my projects and it's wonderful. Haven't experience your problems. There are times of course where you have to understand how maven 2 resolves dependencies, etc..., basically have a good understanding of POM, but that should go for anything we use. Ilya
  13. Re: Maven2?[ Go to top ]

    Is Maven2 usable yet?
    I guess it depends on your patience threshold and how you intend to use it. Like one or two others mentioned, I've integrated it into our build system which is primarily ant-based using 1.6 features such as import, macrodef, subant, among others. Maven as it is currently distributed, turned out to be poor fit for our environment, though I liked the core concepts. In the end, I created a build system that was influenced heavily by Maven, yet leveraged my accomulated experience with Ant along with Ant's easy extensibility. We also benefitted from a wealth of available Ant tasks. Looking back, I see there are similarities to the approach taken with Jam (though I didn't know it at the time). I adopted several Maven conventions in laying out our projects, and we use a small portion of the POM mostly for dependency management. Once we abstracted the maven plugin's tasks behind some friendlier macros, and tweaked the plugin's source to yield better error reporting and easier versioning of multi-project builds, life improved a lot. I feel as though we got many of the benefits of both Ant and Maven, along with a few drawbacks, but all things considered, it's worked out well. If Maven gets to the point where we are ready to completely adopt it in the future, we should now be well-positioned to make the transition easier, though I think we're also easily able to replace the Maven plugin portions with Ivy if we decide to go that way.
  14. Re: Maven2?[ Go to top ]

    I've used Maven 2 for a bit now, and I agree that it still feels a bit "raw" in places, but it's come a long way. I would hope that most/all of the current annoyances would be cleared out in the next few releases.
  15. Java to build Java[ Go to top ]

    It looks like a way of using the java language to build a java project. What we need is a more consise way to describe the build without having the java language/syntax get in the way. Maybe sone kind of build DSL.
  16. Re: Java to build Java[ Go to top ]

    It looks like a way of using the java language to build a java project.

    What we need is a more consise way to describe the build without having the java language/syntax get in the way.

    Maybe sone kind of build DSL.
    I'd think for most of us here the Java language would not be a barrier. In fact, the one language that you would hope Java programmers would all know is, well, Java.
  17. Re: Java to build Java[ Go to top ]

    It looks like a way of using the java language to build a java project.

    What we need is a more consise way to describe the build without having the java language/syntax get in the way.

    Maybe sone kind of build DSL.


    I'd think for most of us here the Java language would not be a barrier. In fact, the one language that you would hope Java programmers would all know is, well, Java.
    I agree, Java would be just fine, *if* it used like Java and not an emulation of an emulation of a bad scripting language. I think we should realize that a build system is an application like all the others, and that we can use the goodies we use for developing applications (layered design, modeling, object orientation) also for builds. My (more) complete discussion of subject is on: http://jroller.com/page/dececco Maurizio De Cecco
  18. Maven 2 is ready[ Go to top ]

    Maven 2 is ready, has been ready for some time, if you can't figure it out, then I'm sorry about that, but there are enough tutorials, examples out there that you can find by yourself by just using Google. If anyone tells you that Maven 2 isn't ready yet, it means that they haven't necessarily used it in the last few months.
  19. It is ant, not just similar[ Go to top ]

    According to the project page, this *is* Ant stripped of its build.xml processing and backward-compatibility features, embedded under an API layer that exposes the tasks as Java objects. It dynamically compiles your build class, but now you need a compiler to run any Ant build, even one that doesn't compile anything except itself. If you thought XML build scripts were hard to read and understand, how is this better? This may be a neat toy (or a complete waste of time, is more like it) for a small project, but imagine how it will fare on a large scale project with a complex build that needs maintenance and release engineers who don't know Java. Not that it really matters, but how does one add new tasks that one downloads off the Web? Just taskdef it? Well, I guess the fact that something like Gosling is possible is more of a testament to the power and adaptive evolution of Ant itself, which used to be rather difficult if not impossible to embed back in the old days. Time would be better spent, IMHO, on a compact syntax for Ant build scripts that is fully convertible from and to a build.xml. Groovy's AntBuilder comes close, but then you need Groovy. With the Ant support in Eclipse, Netbeans and IDEA these days, I, for one, am pretty much all set with Ant and look forward to the upcoming Ant 1.7.
  20. Re: It is ant, not just similar[ Go to top ]

    Using XML for any sort of programming or scripting is generally a bad idea (jelly/xdoclet anyone)? I think a Java developer of even the most basic skill level will have an easier time reading Java code than a custom scripting language in XML. He/she would certainly have an easier time extending it. Just yesterday I had to write a nasty ant script for parameterized calls to an ant target that wasn't fun to write or debug. With gosling, it's a simple Java method that's easier to understand and refactor.
  21. Re: It is ant, not just similar[ Go to top ]

    Using XML for any sort of programming or scripting is generally a bad idea (jelly/xdoclet anyone)?
    Not ever... XML programming is a must if you want to deal with the SGML-Java (or any other non-SGML language) impedance. Most of Java (and non-Java) web frameworks have some kind of XML based programming. Anyway your project rocks, the build process is not a SGML derived paradigm, no strong reason (except aesthetic) to use XML programming. Jose M. Arranz JNIEasy coding C/C++ with Java.
  22. on a large scale project with a complex build that needs maintenance and release engineers who don't know Java.
    Non-Java guys managing a Java project? Changing how is compiled, executed, deployed? Using Ant a Java based and centric tool? Jose M. Arranz JNIEasy is your legacy stuff in C/C++? don't rewrite bring it to Java.
  23. Scripting Build[ Go to top ]

    If you think that a build is really more about scripting than anything else, you may want to have a look at Raven: http://raven.rubyforge.org
  24. Ant without the XML[ Go to top ]

    This is pretty much just Ant without the XML. In that respect, it's probably better that Ant (better debugging). On the other hand, it's not really a different approach (like Maven2 is). I like the idea... But I'll probably wait a bit to see how it evolve. Here is my full take on the subject : http://epirsch.blogspot.com/2006/10/ant-without-xml.html
  25. Re: Ant without the XML[ Go to top ]

    I know exactly what you mean. Right now, it really is just a bare almost wrapper around ant. But the nice thing about it is, that you can just extend Project to create a different type of profile so that you can provide some maven like features such as default project layouts and built in tasks and the like. That's something that's very much on my radar but I need to remove the 1.6 dependency and add support for maven-style dependencies first. Then all sorts of fun stuff can be done.
  26. Comment from the Ant team[ Go to top ]

    As a member of the ant team, here is my unofficial response 1. we welcome all uses of the Ant tasks. There are many products that use ant, from Tomcat and weblogic to luntbuild. 2. remember that the java API has less guarantees for stability than the XML language. We strive for 100% backwards compat in the XML level, about 95% in Java. 3. Dont try and run stuff compiled against a newer version of Ant against an older one. 4. While the limitations of XML are well known, I'm not personally sure that moving to a compile-before-you-build tool is a tangible improvement. Ant-in-scripting language (ie. groovy) may be better. 5. please, please dont ship a custom version of Antwithout renaming the shell scripts. This project hasnt done that, but I know weblogic has and it raises lots of support calls.
  27. don't forget gAnt[ Go to top ]

    http://groovy.codehaus.org/Ant+Scripting ant.sequential { echo("inside sequential") myDir = "target/AntTest/" mkdir(dir:myDir) copy(todir:myDir) { fileset(dir:"src/test") { include(name:"**/*.groovy") } } echo("done") } etc. etc.
  28. Gant![ Go to top ]

    http://groovy.codehaus.org/Gant +Only requires Java 1.3 (as a Groovy dependency) AFAIK. +Less verbose than writing Java (this is _scripting_ after all). +Powered by a rich, standard scripting language. -Currently alpha stage.
  29. Re: Gant![ Go to top ]

    well, all right Gant seems nice but author's point is to leverage Java knowledge.. That is why i liked it. But tool support might be an issue for both projects.
  30. Re: Gant![ Go to top ]

    well, all right Gant seems nice but author's point is to leverage Java knowledge.. That is why i liked it. But tool support might be an issue for both projects.
    But that is the whole point of Groovy and Gant, to build on Java knowledge, and make use of Java libraries, using a dynamic language, which is more suitable for scripting. I agree that using XML for Ant is painful. Gant was created exactly so that Ant tasks, Ivy tasks, etc. could be used from a dynamic programming language to create build systems. SCons, Waf, Rant, etc. have shown that programming build systems in a dynamic language is the way forward. Using these languages to create internal DSLs to describe builds seems natural and efficient -- both for the programmer and the machine. At a rough guess I would say the Gant equivalent of the Gosling program would be: sourceDir = 'src/java' buildDir = 'build' task ( build : 'Builds the Gosling project' ) { Ant.javac ( srcdir : sourceDir , destdir : buildDir ) { compilerarg ( line : '-Xlint:unchecked -Xlint:deprecated -g' ) } } Gosling is clearly a great experiment in trying to do builds with Java but I prefer the Gant route -- but then I suppose I would :-) See http://groovy.codehaus.org/Gant I see great parallels here with XML processing. JDOM and dom4j are better than previous offerings but XMLSlurper and GPath, etc, in Groovy make things so much easier. Especially when you can use Java as well as Groovy to create systems.
  31. Congradulations. I have been looking for such a work for a long time. I do not know the extent and the quality of this work. However, I strongly believe that we should be able to use Java itself to create complex build processes. Another related usage is to use Java itself instead of XML for complex configurations. People are referring to scripting languages. Why should I learn another language or a subset of Java just to write some configuration or build? I do agree that Java for build or configuration is heavy, but if used in complex scenarios, it will definitely be benefitial.
  32. Although I do not like that Ant scripts are XML based, after looking at this Java translation of Ant script I must admit that original Ant script is much more readable! Seriosly, this looks awfull. Maybe the answer is in creating a non-XML based but declarative language for build scrips. But also, maybe the answer is in formentioned Groovy gAnt (I didn't have a chance to look at it). Newertheless, I do not see Ant's XML based syntax as it's main problem. For me, the main problem with Ant is that it is not Turing Complete. Simple constructs like if/else, choose/when/otherwise, looping, try/catch/finally are prohibited in Ant with intention. This is a mistake, as today building a complex system is not a trivial task. For non trivial task we need Turing Complete language. As I am lately working on Java and .NET projects, I had a chance to use NAnt quite a bit. NAnt has all the mentioned basic flow and exception control tasks, and that makes building complex systems much more easier. Also, NAnt has concept of functions and expresions that often come just handy. Just consider following common build steps that require some kind of flow or exception control: - you are installing a new web site or some kind of service. You have different steps to do if you are installing it first time and when just upgrading it. For example, if you are deploying windows service, you have to install it if it's not installed, but stop it if it is already installed and running. If/Else task would be much more readable then having to cope with targets and their conditions. - you want to keep a file with build number in source control. You check-out the file at the begining of build process and increment build number. You want to check-in the build number file back into the source control if build succedded, but you want to undo changes to build number file if build failed. This is hard to do with Ant, but is very easy and readable with NAnt's trycatch task! So, I believe that decision of Ant authors to keep it without basic flow and exception control tasks is a big mistake.
  33. Although I do not like that Ant scripts are XML based, after looking at this Java translation of Ant script I must admit that original Ant script is much more readable! Seriosly, this looks awfull.
    I agree. There's a lot of unecessary plumbing code. Remember me of my Swing programming old days.
  34. Beanshell[ Go to top ]

    This would be even easier using the embedded scripting feature coming in Java 6. That would avoid having to compile the 'build class', and would obviously be scriptable and quicker/easier to use. My choice would probably be to use Beanshell (http://www.beanshell.org) as it offers a zero learning curve to get going. Maybe something like BSF (http://jakarta.apache.org/bsf) would extend this to the pre-Java 6 world?
  35. Listen, the idea of moving from Procedural XML to Procedural Annotated java for something that should never have to be written for every project in the first place is insanity. See Maven 2, get out of the business of constantly telling your projects how to build themselves and cue into the fact that you should never be expressly telling your Java project to compile itself with Javac. That should be a given. The title of this post should be "Gosling: an (idiotic) build process that uses XML instead of Java"
  36. Still writing Ant build file ?[ Go to top ]

    The aim of the build framework EL4ant http://el4ant.sourceforge.net/ is to provide a simple and really fast build system for your multi-component projects. You provide a project description and the Ant build.xml is generated (and Eclipse project files...) If you need extra-features, you can create your own plugin to generate new targets and include Ant tasks. Let's try it - a demo project is available in the bundle.