One of the things I find myself trying to instill in a lot of our developers these days is that a little pragmatism can often go a long way.
By popular demand (really!), here’s my trivial shell script that pretends to be maven. For smallish projects and small sizes of your local maven repository, it is orders of magnitude faster than doing an actual maving run, and it has many other advantages over the “real” maven.
Of course, I don’t actually use this script (much). Lately I’ve been using Ant 1.7 with Ivy. Oh, And mod_perl‘s Apache::Test for TripleSoup.
#!/usr/bin/env bash
artifactId=`xmllint --noblanks project.xml |
egrep -o '<id>[^>]+<\/id>' |
sed -e 's/<id>//' -e 's/<\/id>//'`
groupId=`xmllint --noblanks project.xml |
egrep -o '<groupId>[^>]+<\/groupId>' |
sed -e 's/<groupId>//' -e 's/<\/groupId>//'`
currentVersion=`xmllint --noblanks project.xml |
egrep -o '<currentVersion>[^>]+<\/currentVersion>' |
sed -e 's/<currentVersion>//' -e 's/<\/currentVersion>//'`
shortDescription=`xmllint --noblanks project.xml |
egrep -o '<shortDescription>[^>]+<\/shortDescription>' |
sed -e 's/<shortDecription>//' \
-e 's/<\/shortDescription>//'`
package=`xmllint --noblanks project.xml |
egrep -o '<package>[^>]+<\/package>' |
sed -e 's/<package>//' \
-e 's/<\/package>//'`
organization=`xmllint --noblanks project.xml |
grep -A5 '<organization>' |
egrep -o '<name>[^>]+<\/name>' |
sed -e 's/<name>//' \
-e 's/<\/name>//'`for jar in `find $HOME/.maven/repository -name "*.jar"`; do
CLASSPATH=$CLASSPATH:$jar
done
CLASSPATH=`pwd`/target/classes:`pwd`/target/test-classes:$CLASSPATH
export CLASSPATH
echo Building $artifactId-$currentVersion.jar...
rm -Rf target
mkdir -p target/classes
mkdir -p target/test-classes
cd src/java
javac -nowarn -Xlint:-deprecation -source 1.4 -target 1.4 \
-d ../../target/classes \
`find . -name '*.java'`
for dir in `find . -type d -not -path '*svn*'`; do
mkdir -p ../../target/classes/$dir
done
cp -r `find . -type f -not -name '*.java' -not -path '*svn*'` \
../../target/classes
cd ../..
mkdir -p target/classes/META-INF
cp -f LICENSE* NOTICE* target/classes/META-INF 2>/dev/null
cat > target/classes/META-INF/MANIFEST.MF <<MFEND
Manifest-Version: 1.0
Created-By: Apache Maven Simulator 1.0
Extension-Name: $artifactId
Specification-Title: $shortDescription
Specification-Vendor: $organization
Specification-Version: $currentVersion
Implementation-Vendor: $organization
Implementation-Title: $package
Implementation-Version: $currentVersion
MFEND
cd target/classes
jar cf ../$artifactId-$currentVersion.jar *
cd ../..
echo Installing $artifactId-$currentVersion.jar...
mkdir -p $HOME/.maven/repository/$groupId/jars
cp target/$artifactId-$currentVersion.jar \
$HOME/.maven/repository/$groupId/jars
echo done