Thursday, May 1, 2008

Pimp my Linux: Maven2 Bash Completion

Inspired by this bash completion for ssh, I wanted to see what it would take to do something similar for maven2. Thanks to google it's already been done.

It's not perfect, but it's a start. For example, the choices are hard coded in the script. And when I tab after typing mvn assem it outputs mvn assembly\:assembly. Shouldn't be too hard to find that extra slash.

Here are some thoughts on how one could improve it. First, maybe it could be improved for at least the core plugins by searching the local repo in /m2/repository/org/apache/maven/plugins. Or searching the local repo for any pom that contains a packing value of maven-plugin (maven-plugin). Combine that with the help plugin to get the possible goals and all their parameters and one could probably create a pretty slick and useful bash completion for maven2.

For example, you can get everything you need for any plugin if you know the groupId and artifactid by running this:
mvn help:describe -DgroupId=org.apache.maven.plugins -DartifactId=maven-war-plugin -Dfull=true

I say all this, but I use a lot of alias's for my maven commands. Here are a few of my favorites:

alias mci='mvn clean install'

alias build='mvn clean install -Dmaven.test.skip=true -Dpmd.skip=true -Dcheckstyle.skip=true'

2 comments:

willCode4Beer said...

I've fixed the slash on colons and (IMHO) made it easier to add commands.

I also added some setup stuff for Mac/Win users who aren't accustomed to the sweet life we enjoy with Linux :-)

Take a look:
http://willcode4beer.com/tips.jsp?set=tabMaven

Unknown said...

IMO using help plugin would be to much resource consuming as it needs to run maven which itself is a bit slow.

In this case I prefer more brute-force approach ;-)

It took me some time and work, but I think the result was worth the effort.
Of course it still needs some attention (the idea of searching the local repository seems interesting).