News Ticker

Rebuild a Maven repository in 3 steps

In this blog post, I will show a way to very quickly rebuild a Maven repository without having to set up a project.

Step 1: Delete all artifacts

Cleanse your Maven repository by deleting the contents of the /.m2/repository directory. Ensure to delete the settings.xml file if so required.

Step 2: Create a dummy POM file

Create the simplest POM file that defines only groupId, artifactId, and version. This is just a basic dummy POM file that you will delete later. Maven needs it to run the purging local repository dependencies command.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>most-basic-project</artifactId>
    <version>0.0.0-SNAPSHOT</version>

</project>

Step 3: Repopulate the local Maven repository

Run the purge repository Maven command:

mvn dependency:purge-local-repository

The objective of this Maven goal is to remove artifacts from your local maven repository. It will delete and re-resolve artifacts.

Finally, delete the POM file. Now you have a nice clean Maven repo with freshly repopulate artifacts.

Learn more about Maven from Linkedin Learning

Introducing Maven
Java: Build Automation with Maven
Multi Module Build Automation with Maven
Java: Testing with JUnit

Other Maven articles that may interest you.

Maven Cargo Plugin: WildFly 10.x
Maven compiler arguments

Leave a Reply

%d