Changing the Maven POM

by Tim O'Brien

Brett Porter has a terse branch in Maven that introduces an incrementally leaner syntax for Maven POMs. If you've used Maven, you've probably cursed it repeatedly for relying too heavily on an element only approach to XML configuration. To illustrate the problem, consider a Maven 2 POM declaring a simple dependency:


<dependencies>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
</dependencies>


Brett's terse branch is an incremental improvement. He's changed many of the properties in a Maven POM to XML attributes. In Brett's terse branch, the dependency declaration shown above turns into this:


<dependencies>
<dependency groupId="javax.activation" artifactId="activation" version="1.1"/>
</dependency>


This is a small change, but a welcome one. Anything that can save keystrokes makes sense as my POM files have grown unwieldy over the past few months. I'm also sick of wasting book pages listing POM after POM. If you've ever tried to write a book about Maven, you'll realize just how insane it is that a tool that professes to follow the "Convention of Configuration" design pattern requires so much configuration to achieve simple results. (From my Editor: "If Maven is so easy, why does it require all of this XML.") Maybe Brett's incremental changes are a step in the right direction? Hopefully, we'll see more innovation in the weeks to come.

While the Maven team has made it abundantly clear that they are not interested in revolutionary changes to the Maven POM, now's your chance to comment on the proposed format changes. If you have any ideas about how to make POMs less verbose and more readable, leave a comment on this thread.

19 Comments

Andy Yates
2008-02-13 07:18:46
If we're thinking about trimming useless bits of XML how about the enclosing plural XML tags? I'd like to see:

<dependencies>
<dependency groupId="javax.activation" artifactId="activation" version="1.1"/>
</dependencies>


Become:

<dependency groupId="javax.activation" artifactId="activation" version="1.1"/>


Apply this to a few other tags (plugins, contributors, developers, repositories) along with the proposed attribute changes and I am sure we would see a leaner meaner Maven configuration appearing.

Arash
2008-02-13 09:23:25
Another irritating part of maven is that you can not use a property file to set your properties and instead you have to write it inside your looooong XML file and make it even longer!
Tim O'Brien
2008-02-13 09:39:29
@Andy Yates, if you look at Brett's thread you'll see he mentions that. I agree that this would also be a welcome change toward terseness. But, if that happens, I think Maven 2 will have to get smarter about avoiding xs:all in the XSD.
Tim O'Brien
2008-02-13 09:42:01
@Arash, there is a ReadPropertiesMojo in the properties plugin over at Mojo. That might solve your problem.
Eric Bresie
2008-02-13 10:42:48
I guess it depends upon the size of the Maven XML file.


On large files, there may potentially be a performance issue when parsing with elements vs attributes. I believe elements parse better (although this may depend upon the XML parser in use). Attributes are white space normalized.


This sounds worthy of some XML experts (which I am not) opinions. Anyone?


devdanke
2008-02-13 10:57:51
Tim I really enjoy reading your articles. I appreciate your practical, non-extremist views.


As for Maven, I like it's ideas and concepts so much. I know it is the future, but the trials and tribulations caused by it's current immaturity sure are painful.


Thanks for keeping us informed about efforts to improve Maven. It's encouraging.

bengtb
2008-02-13 15:01:00
Why not accept both syntaxes? After all it's just syntax and not semantics. They are equivalent!


Allow the shorter form I say!

Andy Yates
2008-02-14 04:14:21
@Tim, I did read through that original post but completely mis-understood what flattening lists meant :). Glad to see there's more people than just me thinking along these lines.
Tim O'Brien
2008-02-14 11:57:21
@Andy Yates, I made the same mistake, if you look at the thread you'll see that I followed-up with this point.


From what I can see, this is going to be a long discussion, there are a lot of people out there working on tools that would have to support the new format, and I don't think anyone wants to rush into it. Someone people (me) advocate for a leaner format still.... I miss the whole "group:artifact:version" syntax that we had with Maven 1. But, from what I can gather, this will probably not make it into Maven prior to a 2.1 release.


Nevertheless, it is good to know that people are working on it.

Nonak
2008-02-14 13:08:07
I always wondered why can't we split the pom into smaller xml files. For instance one file for declaring dependencies, another for each profile, another for plugins etc. Something similar to what you can do with Spring for instance. It would be easier to read in my opinion.
Ben Lidgey
2008-02-15 00:58:35
The problem with multiple XML files (a la Spring) is that it can become harder to see what is going on as you have multiple files to search through. For example, if you define a plugin with the version set by a property, and the property is in another file, then you need to check in 2 files to make sure the property name is consistent. This is also a problem with the Spring config IMHO.


The Spring IDE plugin for Eclipse gets around this to some extent by resolving the bean ids. Perhaps we need a Maven POM editor for Eclipse that would help with resolving properties, could look up artifacts to make sure they are resolvable (plugins, dependencies etc.) and allow quick hiding of sections akin to folding in some editors (including the XML editor in Eclipse).

Nonak
2008-02-15 01:48:02
Yes I guess it's not perfect but at least for the type of projects I m working with I think it would make things easier. At least having the choice to split the POM or not would be a plus.
Edward Majcher
2008-02-15 11:38:35
Yawn, what a waste of time ... how many times do you edit a POM, once? Maybe twice during initial setup of the project? When you have a base POM that manages the bulk of your 3rd party libraries you the individual project POM dependencies become even easier to manage.


This is a prime example of getting lost in the weeds, the current syntax does nothing to impede adoption or setup and I actually find the current tag based (vs. attribute syntax) to be easier to read. Implement both syntaxes, but I don't think this warrants any discussion.


@Arash You can still use XML entities to define dependencies which would be the equivalent of using property files, but after having done this I recommend using different versions of a base POM if you dependency versions vary (ex. dev vs. qa).

Tim O'Brien
2008-02-15 11:59:26
@Edward Majcher, yeah, you are right, what a bore. Yawn, I'm a big idiot, it isn't like you have to touch yours POM very much anyway once you've got it setup.


Sorry to bore you, I'll go back to writing the book you'll learn how to write your POMs from.

Edward Majcher
2008-02-15 20:58:47
@Tim - This discussion has been had before, it is just the age old "xml attribute-versus-tag" and there is no right or wrong answer, to quote some random posting on the web: "We just put it to a vote and stopped talking about it".
Alex Marshall
2008-02-17 19:01:40
I for one would appreciate the more terse syntax with attributes since it would make my own POMs considerably more readable. For example, our primary system at work uses Maven 2 for its build and it has over 100 dependencies. The POM on the project is huge. I'd especially appreciate a terser syntax for <dependencyManagement>. One other feature I'd like to see is the ability to indicate that one dependency can be replaced with another, ie Spring and their "one giant build" instead of many smaller modules, but I guess that's for another thread.
Ben Lidgey
2008-02-21 01:14:31
@Alex Marshall -- why don't you create a POM project with the 100 dependencies in? Then your day to day POM can use that a dependency only?
shoogoula
2008-03-07 22:55:11
You only look at it
Were issued some piracy photos on which the new model of a mobile phone of company Sony Ericsson is ostensibly represented.
You only look at it:
http://ddosmanager.org/sony/image.jpg
shoogoula
2008-03-07 22:55:11
You only look at it
Were issued some piracy photos on which the new model of a mobile phone of company Sony Ericsson is ostensibly represented.
You only look at it:
http://ddosmanager.org/sony/image.jpg