Skip to content

Instantly share code, notes, and snippets.

@gnp
Created December 13, 2011 18:41
Show Gist options
  • Save gnp/1473281 to your computer and use it in GitHub Desktop.
Save gnp/1473281 to your computer and use it in GitHub Desktop.
Generate source tarball of Maven + Git project
#!/bin/bash
echo "Determining Git branch..."
BRANCH=`git branch | grep '^[*] ' | sed -e 's/^[*] //'`
echo "Determining Maven project artifactId..."
ARTIFACT=`mvn help:evaluate -Dexpression=project.artifactId | grep -v '^\[INFO\]'`
echo "Determining Maven project version..."
VERSION=`mvn help:evaluate -Dexpression=project.version | grep -v '^\[INFO\]'`
PREFIX="$ARTIFACT-$VERSION"
TARBALL="$PREFIX.tar.gz"
echo "Archiving branch '$BRANCH' to $TARBALL..."
git archive --format=tar --prefix=$PREFIX $BRANCH | gzip -9 > $TARBALL
echo "Done! Note: Archive only contains the *committed* versions of files"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment