Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GrahamLea/6121451 to your computer and use it in GitHub Desktop.
Save GrahamLea/6121451 to your computer and use it in GitHub Desktop.
Reads all dependencies from a Maven project and then deletes them all from your local repository.
#!/bin/bash
#
# Reads all dependencies from a Maven project and then deletes them all from your local repository.
#
# You may want to do this if you want to remove <repository> tags from a POM and check that you can still
# access all the dependencies for the project from just the remaining repositories.
#
# This code is in the public domain and may be used in any way you see fit, with the following conditions:
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
MVN_REPO=$(mvn help:evaluate -Dexpression=settings.localRepository |grep -v "^\[")
TMP_FILE=$TMPDIR/$(basename $0).tmp
mvn dependency:list | tee $TMP_FILE
for artifact in $(cat $TMP_FILE | egrep -o " [^ ]+:[^ ]+:[^ ]+:[^ ]+$");
do
echo "Deleting $artifact"
artifact_path=$(echo $artifact | awk -F: '{gsub(/\./, "/", $1); print $1 "/" $2 "/" $4;}')
rm -r $MVN_REPO/$artifact_path;
done
rm $TMP_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment