Lofi has posted 6 posts at DZone. View Full User Profile

Moving from Ant to Maven: Best Practices with Maven Plugins

  • submit to reddit

I would like to share my experience of moving from "our reinventing wheel" of Ant build scripts to Maven standard.  I reworked some apps which have following characteristics:

Java Version:

  • The apps should be compiled with Java 6 version.
    Basic technologies:

  • Some of the apps are using Model Driven Architecture/Model Driven Software Development things, it means we have some MDA/MDSD generators inside our Ant scripts, like AndroMDA or oAW.
  • Almost all the apps use Hibernate, so we need to generate the whole Database scheme to be able to create the whole database automatically.
  • Some of the apps use older version of ANTLR. So we have some of ANTLR source codes which have to be compiled.
  • Some of the apps use older version of Groovy. So we have some of Groovy source codes which have to be compiled.
  • A webapp uses GWT as presentation layer.

  • Packaging:

  • Some of the webapps have some kind of information about the version. For example the webapps have version.html file which should be automatically generated with some information like build timestamp, the person who build the app, the description of the app, etc.
  • The apps or modules should be packaged as war or jar. Additionally they also include some additional information like installation documentation, SQL scripts, etc. which have to be package as a zip file separately.
  • All of the apps or modules should also package the source codes additionally to the packaged artifacts, so we can debug the apps easily.
  • The webapps need to package the class files additionally as a separate jar file, so that this can be added as a dependency into another Maven project or module.

  • Test:

  • The apps have some unit tests in JUnit.
  • The apps have some integration test for SpringFramework context and database or service methods test in SpringFramework.

  • Optimization:

  • JavaScript, CSS of some webapps should be optimized using YUICompressor.
  • JSP files should be precompiled with JSPC from Weblogic.

  • Quality check:

  • Quality check: the apps should be quality checked using Emma (code coverage) and CheckStyle (quality of the codes).

  • Deployment:

  • The webapps should be automatically deployed to Weblogic.
  • All configurations should be automatically uploaded to the server.
  • The database scheme should be automatically upgraded and downgraded.

  • Development support:

  • JRebel rebel.xml file should be automatically generated for chosen projects or modules.

  • Yes, our Ant scripts can do the (almost) whole things above. You can imagine how complex they are? Yes, everything are in the Ant scripts and you need to turn on/off the features you need. Remember how SAP works? Yes, we call this customizing! This is where I see the power of Maven. The plugin concept is just a better concept. Instead of having everything, we only have a small "core" and we add plugins on the top to fullfil our need. In case of the Ant scripts, you have everything (although you don't need all of them) and then you use switcher to turn them on and off.

    So how did I solve the requirements above with Maven? Here they are, the plugins we need! In this article I just want to show you the plugins I used:

    Continue read this article at: http://lofidewanto.blogspot.com/2011/06/moving-from-ant-to-maven-best-practices.html

    As a conclusion I just can say, Maven and its plugin ecosystem are great. No matter how complex your project you can still handle it easily with Maven plugins. My lessons learned is that DO NOT REINVENTING WHEEL! There are a lot of good Maven plugins out there! In case you cannot find one, just use maven-antrun-plugin. You can almost do everything with it. Just don't forget that you don't want that chaos back to Ant, so use it with precautions.

    ... and to all other developers who still doing their own build processes... try Maven, you won't regret!

    Discussion: so what are your experiences with Maven plugins? What are your favorites Maven plugins?

    From http://lofidewanto.blogspot.com/2011/06/moving-from-ant-to-maven-best-practices.html

    Published at DZone with permission of its author, Lofi Dewanto.

    (Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


    Maheshkumar Per... replied on Wed, 2011/06/29 - 9:08pm

    Its really nice article about maven-plugins for new users. Please update your blog if you come up with new plugins

    Lance Semmens replied on Fri, 2011/07/01 - 7:05am

    Did you consider Gradle instead of Maven? All the cool kids (Hibernate, Spring Integration, Spring Security etc) are doing it ;)



    Lofi Dewanto replied on Mon, 2011/07/04 - 2:40pm in response to: Maheshkumar Periyasamy

    Yes, I'll do it. I'll keep you informed. Thanks, Lofi.

    Lofi Dewanto replied on Mon, 2011/07/04 - 2:49pm in response to: Lance Semmens

    I don't have any experiences in Gradle but one thing I cannot agree: using another DSL would make build management easier.

    IMO adding new languages (DSL) will make everything much more complex and you have to find developers who know those languages. Also you need a good tooling support (editor, etc.), so this is not trivial at all...

    If you have a developer team which is not always uptodate, just stay with Java and XML. I had some bad experiences with Groovy and our own DSL (using ANTLR).

    So, just stay with XML (Maven) and in the future I hope that M2Eclipse will become better and better. At least it is now the part of Eclipse project (see Indigo Eclipse 3.7). So maybe you never had to edit those XML pom file, just edit it with the Eclipse editor ;-)


    Sirikant Noori replied on Sun, 2012/01/15 - 12:05pm

    Thanks for writing this up. I'm considering suggest making the move from Ant to Maven as well and this post will be quite helpful!

    Carla Brian replied on Wed, 2012/06/20 - 6:04pm

    Writing plugins is the best way to extend Maven and continue to share it among other projects. However due to its architecture there are some things that are not recommended. - Instant Tax Solutions Scam

    Comment viewing options

    Select your preferred way to display the comments and click "Save settings" to activate your changes.