execute maven goals in subdirectories.


Update: OS X’s find command doesn’t seem to have -printf option. Not gonna work. Somebody please comment how to fix this.

Update: Changed and works for OS X and Ubuntu.

When you have one or more maven projects in a directory that are not modularized with any parents, you can execute maven goals recursively in that root directory with this script.

_mvn.sh

#!/bin/sh
if [ $# -eq 0 ]
then
    echo no golas
    exit 1
fi
wd=`pwd`
for i in `find . -name pom.xml -type f`
do
    cd -P ${i%/*}
    mvn $*
    cd $wd
done
exit 0

Here comes the faster cleaning version.

_clean.sh

#!/bin/sh
wd=`pwd`
for i in `find . -name pom.xml -type f`
do
    if [ ! -d ${i%/*}/target ]
    then
        continue
    fi
    cd -P ${i%/*}
    mvn clean
    cd $wd
done
exit 0
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s