Created
July 31, 2013 12:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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