Sunday, May 13, 2012

What is a better, simpler and more modern way to build Java Web Applications compared to Maven?


I'm thinking of getting rid of Maven. It's alright for simple applications, but I'm running into problems that I can't solve, nobody else seems to be able to solve them, and even the Maven mailing list doesn't have a solution.



What are some modern build tools for Java that provide what Maven provides, but also are equipped to deal with the challenges of making modern web applications? For example, if I want to use a Javascript minification tool, such as the YUI compressor, it will easily and effortlessly let me compress/aggregate my css and javascript just before the War file is created.





  • Explanation : The problem with maven is that there is no way to do things inside of the war plugin. For example, I want to call the yui compressor just after it copies over the webapp's resources (css, images, javascripts, etc.). If I could do this, it would ensure that any uncompressed javascript files (that were excluded in the YUI compressor's minification/aggregation process) were part of the final war package. This is not possible



    The YUI compressor only works if you plan on compressing and/or aggregating all your files as opposed to a subset. There are javascript files like jscharts.js where you need to exclude them from the minification process because they otherwise mess up the actual source code. There is no way to deal with this use-case in Maven, even though the solution is simple.





Having the ability to use live javascript vs. compressed/aggregated javascript would also be a big boon.





  • Explanation : It's also hard to refactor your massive javascript includes with those in your html files. Let's say you have 100 javascript files, and you want the ability to use your live javascript files for development, but you want to use the compressed/aggregated ones for production. You still need to include all the javascript files in your html templates (freemarker for example) because you want to deal with the live ones during development. For production, you also have to maintain a separate list in the maven pom.xml as well, in order to aggregate them.



    Both of these lists of javascript files are basically identical, and it's an extra burden for the developer to ensure they include the same files and in the same order :( Maven isn't helping with such a common web-related problem for year 2011. The Rails 3.1 folks though get this for free. We can do better.





I still need the ability to have filters, just like in maven, to handle different production environments. For example, I often use property files to change values in the applicationContext.xml for Spring, or the servlet context.



I also need the ability to add resources to the classpath. I have these massive text files that provide me with the basic functionality of a dictionary, thesaurus, etc. I need to put these in my classpath.



It would be great if the build tool also used the Maven repositories.



Any other benefits, such as more simplicity and writing less configuration code would be a plus, but the features I listed above are paramount.



Thank you.


Source: Tips4all

2 comments:

  1. You ought to be able to do all of that in Gradle. Essentially, its a set of libraries and modules in Groovy that give you a lot of power for putting together your build. If you need to extend it, then you write your extension in Groovy. Its quite nice.

    ReplyDelete
  2. If you are into learning Scala then I highly recommend SBT. We use it to build all our Java code and have been perfectly happy with it. It does neat things such as parallel builds and unlike ANT/Maven its incremental compilation actually seams to work. Also it includes a nice REPL that allows you to interact directly with the build and your code.

    SBT is easy to extend as it's build files are written in code rather than XML. So plugins exists for everything your heart can desire, for example:


    YUI compressor
    CoffeeScript


    As for project dependencies, these can be both managed (downloaded automatically from Maven/Ivy) or unmanaged (i.e. resources (jar's, files, ...) you add yourself) - they can also be mixet and matched.

    SBT uses the standard Maven directory layout (although this can easily be changed), has great support for IDE's (fx. Eclipse and Idea) and it can also produce a pom file for you if you should so desire.

    There is a very good guide to get you started quickly with SBT here

    ReplyDelete