Maven 3.0 Project Model and Mixins

November 7th, 2008 By shane

The Apache Maven project model consists of a fairly rich model structure, consisting of 465 possible elements, specifying everything from the plugins Maven uses to build the project to the dependencies it needs for compiling. How Maven processes the model prior to a build can be a little confusing, dealing with the inheritance of parent poms (or the super pom), the applying of profiles, the merging in of dependency management information, to name just a few of the operations.

Back in May, Jason started talking to me about adding in mixin support for the pom, and it became clear that we needed to reconsider the Maven 2.0 design of project builder so that we could support such features. Maven 2.0 took the approach of merging trees of information (XML nodes), a perfectly reasonable approach for single inheritance. For things like mixins and multiple pom inheritance, linearizing the information proves a much simpler approach.  In this post I discuss the ramifications of linearizing POM information to support multiple inheritance for POMs.

To linearize, of course, means that we have to flatten the XML nodes. I did this by creating a list of model properties, consisting of a URI and a value. So for example, the version would be modelProperty(“http://apache.org/maven/project/version”, “1.0″). The Maven 3.0 project builder creates a rather large list of model properties, stacking them, the child model properties being on top, while each of the parent model properties are placed lower in the list. Inheritance is now just a matter of sorting and removing model properties according to a set of rules.

To see how easy mixins is under linearized inheritance, let’s say we have project A and project B, where project B is the child. Under single inheritance, Maven applies the sorting rules. For a mixin, we just place its model properties below project B’s properties in the list and above those of project A. Maven applies the same sorting rules as single inheritance and doesn’t care whether it’s dealing with a parent model, a mixin or even a second parent model.

I’ve created a detailed specification of how Maven builds the project model, which I will be releasing shortly, giving all the precise rules Maven 3.0 follows for project construction.

 

Maven ,

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

  1. November 8th, 2008 at 11:00 | #1

    Maven is more adopted that in its earlier 1.x versions. People are still not afraid to try and to use it. Maven is really getting better. IDEs are providing great plugins for Maven, no need to use the command line all the time like before.

    However, I do miss time to time Commons Jelly. Maven was far more flexible even if it was slower to start and to run. One could script the maven.xml easily, call ant tasks directly or use other jelly tags. Now everything depends on plugins.

    Time to time, you want to copy a directory or perform some actions at a given step of the build and the only option you have is to write a plugin in plain Java(because it doesn’t exist). I also hope that, Maven will support features like multiple source/test folders out of the box.

  2. November 27th, 2008 at 15:46 | #2

    Hi Yves, I guess you’re talking of what can only be done at the moment with the helper plugin. Maybe you could file an improvement in the tracker to ask for this particular improvement. That’ll help maven developers to track this down and eventually to discuss their view for this feature.

    You can also start by posting a thread on the maven ML about that.

    Cheers.

  3. March 18th, 2010 at 14:28 | #3

    cheap car insurance 347 homeowners insurance nnvps auto insurance quotes zmhrth home insurance 994395

  1. No trackbacks yet.