Git Product home page Git Product logo

mvn-repo-cleaner's Introduction

mvn-repo-cleaner - Maven Repository Cleaner is a utility to clean up the local .m2 directory on a developer box.

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.

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 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.

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

Options:

--accessedBefore, -ab
  Delete all libraries (even if latest version) last accessed on or before 
  this date (MM-DD-YYYY).
  Default: 0
--accessedAfter, -aa
  Delete all libraries (even if latest version) last accessed on or after 
  this date (MM-DD-YYYY).
--deleteAllSnapshots, -dsn
  Delete all snapshots irrespective of being latest.
  Default: false
--deleteJavadoc, -djd
  Delete javadocs for all libraries.
  Default: false
--deleteSource, -dsr
  Delete sources for all libraries.
  Default: false
--downloadedBefore, -db
  Delete all libraries (even if latest version) downloaded on or before 
  this date (MM-DD-YYYY).
  Default: 0
--downloadedAfter, -da
  Delete all libraries (even if latest version) downloaded on or after 
  this date (MM-DD-YYYY).
--dryrun, -dr
  Do not delete files, just simulate and print result.
  Default: false
--forceArtifacts, -fa
  Comma separated list of groupId:artifactId combination to be deleted.
--forceGroups, -fg
  Comma separated list of groupIds (full or part) to be deleted.
--ignoreArtifacts, -ia
  Comma separated list of groupId:artifactId combination to be ignored.
--ignoreGroups, -ig
  Comma separated list of groupIds (full or part) to be ignored.
--path, -p
  Path to m2 directory, if using a custom path.
--retainOld, -ro
  Retain the artifacts even if old versions. Only process the configured inputs.
  Default: false

Feel free to raise any issues or recommend any changes or improvements.

mvn-repo-cleaner's People

Contributors

dependabot[bot] avatar eduarddrenth avatar packpaul avatar techpavan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mvn-repo-cleaner's Issues

Directory has to be called "repository"

I tried use this utility, but with no luck.
I wanted clean repository located in Jenkins controller node (not important)

Important is that repository is located in this directory:
/data/app/tomcat/temp/repositoryconnector-repo/
But it is not possible, because you can specify "--path" parameter but to this path is appended directory name "repository".

I do not understand this limitation and feel free to close this issue. I just want let you know why I cannot use it.

Code responsible for appending "repository" to path

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

Will not compile with Java 11+

Java 8 - mvn package succeeds
Java 11+ will fail with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project mvn-repo-cleaner: Fatal error compiling: java.lang.ExceptionInInitializerError: com.sun.tools.javac.code.TypeTags -> [Help 1]

Error on SH

total 3372
drwxrwxr-x  2 jenkins jenkins    4096 Sep  7 09:47 .
drwxr-xr-x 28 jenkins jenkins    4096 Sep  7 09:45 ..
-rwxr-xr-x  1 jenkins jenkins      51 Jan 21  2018 execute.sh
-rw-r--r--  1 jenkins jenkins 3432440 Jun  3 16:59 mvn-repo-cleaner.jar
-rw-r--r--  1 jenkins jenkins    2394 Jun  3 16:25 README.md
-rwxr-xr-x  1 jenkins jenkins      55 Jan 21  2018 simulate.sh
jenkins@fry:~/mavencleaner$ ./simulate.sh
**/usr/bin/env: ‘bash\r’: No such file or directory**

result empty althought dependencies exists

[jenkins@altair31jenkinsintboappli1 mvn-repo_cleaner]$ java -jar mvn-repo-cleaner.jar
*********** Files to be deleted ***********

FORCED_SNAPSHOT :

FORCED_SOURCE :

FORCED_JAVADOC :

ACCESS_DATE :

DOWNLOAD_DATE :

NON_LATEST :

FORCED_ARTIFACT :

FORCED_GROUP :

*********** Files skipped ***********

RESERVED :

LATEST :

IGNORED_GROUP :

IGNORED_ARTIFACT :

RETAIN_OLD :

*********** Beginning to Delete Files ***********

*********** Deletion Completed ***********

*********** Files having error in deletion ***********

Add option '--downloadedAfter, -da'

I was using a separate <project1>/_m2/repository and by mistake started a build for an other project by

$ mvn -s <project1>/_m2/settings.xml

instead of

$ mvn -s <project2>/_m2/settings.xml

And after this m2-repository of the first project got littered. Now I would like to clean artifacts that were downloaded today.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.