On a CI build server, the local Maven repository fills up the file system repetitively (after a few days). What strategy are others doing to trim the local repository in such a case? -Max
To clear/delete your local maven repository cache, simply delete the . m2/repository folder. The local repository path can also be configured in Maven setting. xml (either the global or the user one).
Just open eclipse-->window-->preferences-->maven-->user settings-->in there see "local repository location". then find the location for your . m2/repository folder then delete that folder if your maven doesn't work properly.
mvn clean: Cleans the project and removes all files generated by the previous build. mvn compile: Compiles source code of the project. mvn test-compile: Compiles the test source code.
The first place that Maven looks for artifacts is in the local repository, which is the local cache where Maven stores all of the artifacts it has downloaded or found elsewhere. The default location of the local repository is the . m2/repository/ directory under the user's home directory.
The Maven dependency plugin has a purge-local-repository goal that allows you to delete the dependencies for a given project from the local repository, if this is run say once a day on each project the snapshots will not accumulate.
Alternatively there's a more scorched-earth approach you could take. As the problem is typically the timestamped snapshot artifacts, you could use the maven-antrun-plugin to delete all files that match the resource collection pattern.
For example (note this might need some tweaking as I've done it from memory):
<plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>package</phase> <configuration> <tasks> <delete> <fileset dir="${settings.localRepository}"> <include name="**/*.jar"/> <exclude name="**/*.pom"/> <exclude name="**/*.war"/> <exclude name="**/*.ear"/> <exclude name="**/*.md5"/> <exclude name="**/*.sha"/> <!--any other extensions?...--> <!--match the timestamp pattern--> <containsregexp expression="[0-9]{8}.[0-9]{6}-[0-9]+"/> </fileset> </delete> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
If you're using hudson, you can set up a scheduled job to just delete the entire repository once a day or something like that. I've got a job called hudson-maven-repo-clean
which has this configuration:
rm -rf ~hudson/.m2/repository
0 0 * * *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With