|
|
Log in / Subscribe / Register

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Chris Hardin reviews Maven 2.0, a cross-platform Java project creation and management tool. "Maven is the new kid on the block, much like Ant was just a few short years ago. Maven 1.0 has been around for a few years and it was accepted by a wide audience of developers as an Ant replacement, but it offered very little relief from the old Ant build.xml file. Maven 1.0 was slow and clunky and using it was almost as difficult as getting started on a project with Ant. In fact, it was Ant at its core, and after an almost complete rewrite, Maven 2.0 was born."

to post comments

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 17:13 UTC (Thu) by ctwise (guest, #10952) [Link] (1 responses)

This is how you create a web project:

mvn archetype:create -DgroupId=com.oreilly -DartifactId=Oreilly -DarchetypeArtifactId=maven-archetype-webapp

And this is the _simplified_, re-written Maven.

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 19:23 UTC (Thu) by flewellyn (subscriber, #5047) [Link]

Having used Maven on a body of Java code that defined several interconnecting modules, I can tell you that it does not scale up well. It's overly complicated, too rigid in areas that should be flexible, while requiring too much explicit configuration in areas that should have sensible defaults, and displays the ususal Java-world fetish for XMLing everything in sight. This is painful when dealing with a small project, crippling with a large one.

It looks to me like what they really want is something akin to MK:DEFSYSTEM or ASDF from the Lisp world, but without all the convenience and ease of use. This is not surprising to me, since in general, Java coders seem to want Lisp without the good bits.

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 19:24 UTC (Thu) by beoba (guest, #16942) [Link]

I had tried using Maven to set up easier builds for a set of interdependant projects. Due to the near-total lack of documentation at the time for the 2.0 series, we went back to using Ant scripts.

This was experienced around January, the documentation might be more existent nowadays.

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 21:41 UTC (Thu) by skitching (guest, #36856) [Link]

I've been experimenting with Maven2 for a couple of open source projects, and really like it. The design is very elegant and reasonably flexible. Yes, documentation is not its strong point at the moment, but it's not too bad. An OReilly book is in progress that will be available online for free which should fix many of the remaining issues.

At work, I'm having to set up a complex build using Ant, and I *yearn* for maven. So much Ant buildfile stuff I'm doing would just be automatic in Maven...

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 21:41 UTC (Thu) by mikov (guest, #33179) [Link] (7 responses)

Such overly enthusiastic articles always make me suspicious. I mean, the author praises Maven for easily creating the project structure - that is a bit much. Without installing Maven anybody could type:

mkdir -p myapp/src/main/java/com/oreilly
mkdir -p myapp/src/test/java/com/oreilly

Not that hard :-)

I also noticed the particularily narrow explanation of the defficiencies of "make" for Java projects. "Not platform independant" is not an argument - there is a GNU make for all platforms that a Java programmer would use. "Isn't easy to use", although correct, is also a claim that requires some justification.

The truth is, "make" is a PITA to use for Java because it cannot ellegantly handle the directory structure of a Java project.

Ant makes mundane Java tasks like compiling a directory structure or creating archives easy, and it has powerful primitives for working with "filesets", but other than that it is a terrible hack. It doesn't even support basic file dependencies. It lacks conditional evaluation. It isn't a general-purpose build tool and so sometimes can be very hard to use even for simple things. As an example, Ant cannot be used to build even a simple "C" project.

Maven makes yet another set of mundane tasks easy - obtaining libraries, deploying etc, but how does it fare as a general purpose build tool ?

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 22:17 UTC (Thu) by iabervon (subscriber, #722) [Link] (6 responses)

Actually, make is awkward for Java because the Java compiler generates object files you can't easily predict, it is slow to invoke the compiler individually on a bunch of source files that need recompilation, and it's hard to get properly-formatted dependancy information.

The directory structure isn't really an issue at all (except, I think, pre-3.80 make would think that it can't create classes/foo/Bar.class with a pattern rule if classes/ or classes/foo/ doesn't exist); you obviously don't want to use recursive make per directory, but recursive make is just a bad idea in general, so this isn't a big deal.

The main thing is that make doesn't have suitable implicit rules for Java, and people don't know how to write a complete Makefile from scratch. (And there isn't a well-known Java build system in make to include.)

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 22:43 UTC (Thu) by mikov (guest, #33179) [Link] (3 responses)

I basically agree - make is hard to use with Java for several reasons. My beaf is with Ant, which I think is terrible for anything besides compiling Java :-)

I am not a make expert. At one time I tried to create a "general purpose" Java make file and I couldn't get it to work right. How do you tell make that there are dependencies between several directories, like this for example:

src/main/java/** -> target/classes/**
src/linux/java/** -> target/classes/**
src/test/java/** -> target/test-classes/**

Note that src/main/java/ and src/linux/java/ both go to target/classes/, while src/test/java/ goes to target/test-classes/. There can be artbitrary interdependencies between src/main/java/ and src/linux/java/, and of course src/test/java/ relies on src/main/java/ and src/linux/java/ .

It is a mess. One of the problems I had was that even after "make" figured out the dependencies, I couldn't get it to produce "bare" file names - I needed "org/foo/bar.java" instead of "src/main/java/org/foo/bar.java".

Eventually I decided that the bulk of the work would have to be done with external scripts and in that case there was not much point in using make in the first place.

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 30, 2006 23:06 UTC (Thu) by iabervon (subscriber, #722) [Link] (2 responses)

I think what you want for your build rules is:

$(OBJECTS_FROM_MAIN):target/classes/%.class: src/main/java/%.java
$(OBJECTS_FROM_LINUX):target/classes/%.class: src/linux/java/%.java
$(OBJECTS_FROM_TEST):target/test-classes/%.class: src/test/java/%.java

The hard thing is getting the "gcc -M"-style output for the other things that a class depends on than its own source (files used as headers, essentially).

It's not too pretty, and it doesn't do any better at making clean builds than Ant (currently), but you can try looking at my java build system, which is available in git in http://iabervon.org/~barkalow/scm/java-iabervon.git/ (sorry, not git daemon yet, and my tarballs are out-of-date).

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Apr 1, 2006 21:50 UTC (Sat) by mikov (guest, #33179) [Link] (1 responses)

I will most definitely check out your build system (I have to figure out how to use git). If it works, even slower than Ant, I will definitely consider using it. In my experience Ant is completely incapable of handling "non-standard-java" projects, for example a project which must be compiled differently for a different OS (similar to SWT). Ant is also total paint to use with GCJ, and completely hopeless if you are using CNI.

About getting the dependancies for a class: Ant isn't in a better position to know the dependancies, so it shouldn't matter. Actually Ant's "depend" task can be used from the Makefile using an adapter app.

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Apr 2, 2006 16:08 UTC (Sun) by iabervon (subscriber, #722) [Link]

I've actually got a gcj version there (set up to compile to .o, but that can be changed), which is somewhat more capable (since gcj has a -M option, which even gives correct results), but I'm not using it, because I need Java 5, which gcj doesn't yet handle.

In my experience, Ant is hopeless with respect to dependancies. I'm unsatisfied with make for Java in comparison to make for C, not in comparison to anything else for Java. (Although I haven't gone through the test case for the Sun javac bug in computing dependancies I found; last I checked, there was a case in which it would output an class file during a failed build and then assume on future runs from the presence of that class file that it had successfully generated some class files that it didn't generate at all)

Maven 2.0: Compile, Test, Run, Deploy, and More (O'ReillyNet)

Posted Mar 31, 2006 11:33 UTC (Fri) by NAR (subscriber, #1313) [Link] (1 responses)

I've used Jam. However, it doesn't seem to be well maintained and I inherited most of the Java-related rules so I'm not sure how hard is it to initially set up. But it's definitely easy to use.

Bye,NAR

Jam and BJam/BBv2

Posted Mar 31, 2006 17:49 UTC (Fri) by scripter (subscriber, #2654) [Link]

You may want to try BJam and Boost Build version 2: http://boost.org/boost-build2/


Copyright © 2006, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds