MAVEN PLUGIN(S) SERIES - Housekeeping of dependencies



PROBLEM 

After a continuos use of maven for project lifecycle management , usually, the local dependencies' repository growth, risks to go out of control.

SOLUTION

There are some plugins that help us to do housekeeping on local dependencies' repository.
This plugin contains various small independent goals to assist with the Maven build lifecycle.
    The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

The goal remove-project-artifact of builder-helper plugin, remove project's artifacts from local repository and it's useful to keep only one copy of large local snapshot.

The goal purge-local-repository of maven-dependency plugin, remove the project dependencies from the local repository.

I suggest you to take a look at both of them in order to understand their features, that offer us a wide range of possibilities.

Utility

To give you an idea of capabilities, below you find an interactive shell script that i've developed to perform the local dependencies housekeeping in easy way. Feel free to use it and let me know your feedbacks.

such script has been realized only for unix/osx systems, but i guess will be  simple translate it for windows.


mvnhousekeeping.sh
clear
echo -n "clear project's targets"
mvn -o clean 

echo -n "delete project's artifacts from local repo [y/N] "
read -n 1 del

if [ "$del" == "y" ] ; then
 echo -e "\nperform delete "
 
 mvn $@ -fn -o \
  org.codehaus.mojo:build-helper-maven-plugin:1.8:remove-project-artifact \
  -Dbuildhelper.failOnError=false \
  -Dbuildhelper.removeAll=true
  
else
 echo -e "\nskip delete "
fi

echo -n "delete project's dependencies from local repo [y/N] "
read -n 1 del

#echo "$del"

if [ "$del" == "y" ] ; then
 echo -e "\nperform delete "
 
 mvn $@ -fn -o \
  org.apache.maven.plugins:maven-dependency-plugin:2.8:purge-local-repository \
  -DreResolve=false \
  -DsnapshotsOnly=false \
  -Dverbose=true
  
else
 echo -e "\nskip delete"
fi

Comments

Popular posts from this blog

POLYMER + TYPESCRIPT the marvelous couple

PlantText: The new "Online" UML Editor powered by PlantUML

PlantUML & Maven - Enrich your project's documentation