Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target/
.classpath
.project
.settings/
dependency-reduced-pom.xml
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
As newer versions of dependent libraries appear, the old ones become obsolete
and never get cleaned up.
This program assists to free up some disk space by removing older versions of
libraries downloaded to the `.m2` directory.
libraries downloaded to the local Maven repository.

This can be used just by extracting `mvn-repo-cleaner.tar.gz` / `mvn-repo-cleaner.zip`
and executing the `execute.sh` / `execute.bat` as per the environment
to clean up all non-latest versions of the libraries in the `.m2` directory.
to clean up all non-latest versions of the libraries in the `<user_dir>/.m2/repository` directory.

If the local repository is in a different location, use the `--path` flag to specify its location.

To attempt a `dry-run`, just execute the `simulate.sh` / `simulate.bat`
to see the files that would be removed without actually deleting the files.
This output is also generated in the `mvn-repo-cleaner.log`.

To run with more advanced options, open the terminal and execute the jar with
appropriate switches as provided below.

**NOTE:** When using the `--path/-p` option, the target it points to must contain a directory (or symlink) called *repository*. This might be needed when cleaning a local directory used for publishing.
To run with more advanced options, run the `execute` script with the flags below.

`Usage: java -jar mvn-repo-cleaner.jar [options]`

Expand Down Expand Up @@ -58,7 +57,7 @@ appropriate switches as provided below.
--ignoreGroups, -ig
Comma separated list of groupIds (full or part) to be ignored.
--path, -p
Path to m2 directory, if using a custom path.
Path to local Maven repository if not in <user_dir>/.m2/repository.
--retainOld, -ro
Retain the artifacts even if old versions. Only process the configured inputs.
Default: false
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.github.techpavan</groupId>
<artifactId>mvn-repo-cleaner</artifactId>
<version>1.0.2</version>
<version>1.1.0</version>

<dependencies>
<dependency>
Expand Down Expand Up @@ -103,4 +103,4 @@
</plugins>
</build>

</project>
</project>
2 changes: 1 addition & 1 deletion src/assembly/scripts/execute.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java -jar mvn-repo-cleaner.jar
java -jar mvn-repo-cleaner.jar %*
2 changes: 1 addition & 1 deletion src/assembly/scripts/execute.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
java -jar mvn-repo-cleaner.jar
java -jar mvn-repo-cleaner.jar "$@"
2 changes: 1 addition & 1 deletion src/assembly/scripts/simulate.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
java -jar mvn-repo-cleaner.jar -dr
java -jar mvn-repo-cleaner.jar -dr %*
2 changes: 1 addition & 1 deletion src/assembly/scripts/simulate.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
java -jar mvn-repo-cleaner.jar -dr
java -jar mvn-repo-cleaner.jar -dr "$@"
2 changes: 1 addition & 1 deletion src/main/java/com/github/techpavan/maven/ArgData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Data
public class ArgData {

@Parameter(names = {"--path", "-p"}, description = "Path to m2 directory, if using a custom path.")
@Parameter(names = {"--path", "-p"}, description = "Path to local Maven repository if not in <user_dir>/.m2/repository.")
private String m2Path;

@Parameter(names = {"--downloadedBefore", "-db"}, description = "Delete all libraries (even if latest version) downloaded on or before this date (MM-DD-YYYY).", converter = DateToMillisConverter.class)
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/github/techpavan/maven/CleanM2.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ public static void main(String[] args) {
}

private static File evaluateM2Path(JCommander jCommander) {
String m2Path = defaultString(argData.getM2Path(), concat(USER_HOME, ".m2"));
String m2Path = defaultString(argData.getM2Path(), concat(concat(USER_HOME, ".m2"), "repository"));
File m2Dir = new File(m2Path);
File repoDir = new File(m2Path, "repository");
if (!m2Dir.exists() || !repoDir.exists()) {
if (!m2Dir.exists()) {
log.error("Valid Maven repository could not be found. Please provide a valid input.");
jCommander.usage();
System.exit(1);
}
return repoDir;
return m2Dir;
}

private static JCommander parseInputParams(String[] args) {
Expand Down