The Maven repository cleaner (bash script), which keeps only the latest versions of artifacts.
This is a fork from alitokmen/maven-repository-cleaner.
The bash maven-repository-cleaner.sh
script
- verifies if the chosen directory is the root of the maven repository
- has the function,
cleanDirectory
, which is a recursive function looping through the~/.m2/repository/
and does the following:- When the subdirectory is not a version number, it digs into that subdirectory for analysis
- When a directory has subdirectories which appear to be version numbers, it only deletes all lower versions
- shows the used amount of diskspace before and after the clean up
In practice, if you have a hierarchy such as:
artifact-group
artifact-name
1.8
1.10
1.2
the maven-repository-cleaner.sh
script will:
- Navigate to
artifact-group
- In
artifact-group
, navigate toartifact-name
- In
artifact-name
, delete the subfolders1.8
and1.2
, as1.10
is superior to both1.2
and1.8
Just use the below three lines, either at the beginning or at the end of the build:
cd <maven-repository>
./maven-repository-cleaner.sh
cd <maven-repository>
./maven-repository-cleaner.sh -y
cd <maven-repository>
wget -S -N https://raw.githubusercontent.com/the-oglow/maven-repository-cleaner/1.00.00/maven-repository-cleaner.sh
chmod +x maven-repository-cleaner.sh
./maven-repository-cleaner.sh -y
Only ONE limitation:
- The tool believes, for example, that the version
1.1
is older than the version1.1-alpha-2
This forked tool is still licensed under the MIT License.
NOTE: No tests in this project!