Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purge artefacts with maven-dependency-plugin

I want to run mvn command to get rid of all artefacts under ~/.m2/repository/here/goes/my/groupid. In order to do so, I run:

mvn -pl my-module dependency:purge-local-repository -DresolutionFuzziness=groupId -Dinclude=<here-goes-my-groupid> -DactTransitively=false -DreResolve=false -Dverbose=true

This works fine, as long as the current version (3.0.0) of the current artefact (my-maven-plugin) is in the local repo.

If the current version (3.0.0) of the current artefact (my-maven-plugin) is not in the local repo (e.g. there is only an older version of this artefact in the local repo, say 2.9.0), nothing gets purged:

[INFO] --- maven-dependency-plugin:3.0.0:purge-local-repository (default-cli) @ my-maven-plugin ---
Downloading: https://repo.maven.apache.org/maven2/here/goes/my/groupid/my-maven-plugin/3.0.0/my-maven-plugin-3.0.0.jar
[INFO] Unable to resolve all dependencies for : <here-goes-my-groupid>:my-maven-plugin:3.0.0. Falling back to non-transitive mode for initial artifact resolution.
[INFO] No artifacts included for purge for project: <here-goes-my-groupid>:my-maven-plugin:maven-plugin:3.0.0

I don't understand why maven-dependency-plugin tries to download anything from maven central. All it should do is to recursively drop a folder in local filesystem.

How can I enforce purging all artefact under given groupId, no matter if the current version of the current artefact is in the local repo or not?

like image 888
automatictester Avatar asked Nov 20 '22 06:11

automatictester


1 Answers

include expects the groupId of the dependency being purged to be exactly same as that of the project. The options resolutionFuzziness, actTransitively and reResolve apply only when the said groupId condition is satisfied. I guess, this might be because the plugin developers want to prevent the accidental purging of artifacts that are out of project's group. It's my wild guess though.

Relax! manualInclude comes to the rescue. It can purge the artifacts irrespective of the project's groupId.

Try this:

mvn dependency:purge-local-repository -DmanualInclude=<group-id>:<artifact-id>

or this:

mvn dependency:purge-local-repository -DmanualIncludes=<group-id>:<artifact-id>

However, the difference is that unlike include it doesn't re-resolve the artifact after purge, no matter what value you give to reResolve.

This condition skips the re-resolve.

like image 174
Sid Avatar answered Dec 28 '22 07:12

Sid