Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purge Maven Local Repository and Keep Latest?

How can I easily remove all stale snapshots from my local repo?

Many files in my repo results in poor performance and the time to fetch artifacts is long. I'd like to keep the repo trimmed down to latest snapshot.

I see that dependency:purge-local-repository can clear the local repository but I want to keep latest. I can easily create a script to do this work (and wrap it in a plugin) but don't want to re-invent the wheel if there's already a tool to purge down to latest.

Is there a plugin that can purge my dependencies to latest-snapshot or last X snapshots?

like image 554
Peter Kahn Avatar asked Sep 24 '12 20:09

Peter Kahn


2 Answers

With Peter's solution, all old versions of current artifact (or group of artifacts, if applied in a parent pom) are deleted, including releases and all snapshots.

If any other projects needs a previous release version, will have to be downloaded again from your non-local repository (say Nexus), and once you create a 'package' of this snapshot, will be deleted again.

I've seen another option for this issue: http://maven.apache.org/plugins/maven-dependency-plugin/purge-local-repository-mojo.html

Has the option of defining 'snapshotsOnly', and will remove only snapshots, not previous stable releases.

like image 85
carbavi Avatar answered Oct 19 '22 23:10

carbavi


This is similar to how-do-you-deal-with-maven-3-timestamped-snapshots-efficiently

I added the following and each build's package clears out the old snapshots keeping my local repository trim and ensuring faster builds on windows which has issues with a bulky repo

     <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.7</version>
        <executions>           
            <execution>             
                <id>remove-old-artifacts</id>             
                <phase>package</phase>             
                <goals>               
                    <goal>remove-project-artifact</goal>             
                </goals>            
                <configuration>  
                    <removeAll>true</removeAll><!-- remove all versions of built artifacts including all versions.  Install phase will regenerate -->             
                </configuration>          
                </execution>         
        </executions>             
    </plugin>
like image 44
Peter Kahn Avatar answered Oct 19 '22 23:10

Peter Kahn