Saturday, February 25, 2017

Pimp my Linux Maven2 Bash Completion

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 its already been done.

Its not perfect, but its 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. Shouldnt 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 aliass 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


Available link for download