Friday, August 17, 2007

Maven Less Ugly

OK - I know I said I wanted to clean up the POM this summer. Well, the season wanes and it is still not done... mostly because I am barely involved with the Maven project these days, though I am apparently still speaking at Apache Con US, OSSummit in Hong Kong, and will talk at the St. Louis JUG on Sept 13 -- but mostly to fulfill promises. Speaking of promises, here is something I whipped up two nights ago whilst at the AIR Bus Tour.

It is a YAML to POM converter:

Cool, eh? It converts a nice little compact YAML file into a giant ugly (and I do mean ugly) POM file.

For example - this concise 37 line "pom.yml" file:

Notice the profiles using a node reference (&core). This is a built-in YAML feature which makes it trivial to reuse giant redundant blocks of configuration, and only overwrite the values you want (in the example above, we overwrite the profile ID to be "test".

Gets converted to this 103 line pom.xml mess by running ./yaml2pom.rb pom.yml:

Not a great example, really. It's nicer if you have a mountainous dependency list. Also, it'd be cooler if the POM wasn't nigh-gobbeldygook. Of course - you shouldn't really need to manage the POM xml if you use this script (and IDE integrations) anyway.

You know - if you really wanted to be slick, you could add something like
exec "ruby yaml2pom.rb pom.yml"
to your mvn (or equivalent mvn.bat version). Then you could make projects with pom.yml files instead of pom.xml... the script will just generate pom.xml prior to execution.

Naturally, it helps if you know YAML.

5 comments:

Wilfred Springer said...

Nice! Are you aware of anyone trying to use a YAML by replacing the XML parser by something that is capable of reading YAML? (Like, using JAXP properties, or something?)

Xavier Hanin said...

Excellent! Finally a way to have shorter poms, I like that.
One question: do you know a good yaml editor?

Eric said...

Well, if you run OSX, TextMate is the greatest. I'm afraid I don't know one for windows, except maybe Notepad++.

Eric said...

Wilfred -
If not me, then I doubt anyone. It would take a change to several core implementations to make a pluggable parser, which I don't see coming until post Maven 2.1.

Bert said...

How about updaing maven to include a pre parser hook, where before the parser reads a pom file, you can read your own yaml, generate the pom, then feed this into the parser, either by replaceing the xml pom or by supplying an input stream