Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I remove jar from local repository without pom.xml?

I install my jar to local repository by command:

mvn install:install-file -Dfile=aaa.jar -DgroupId=bbb -DartifactId=ccc -Dversion=1.0 -Dpackaging=jar

Now I want remove it from repository. I try command:

mvn dependency:purge-local-repository -DmanualInclude=bbb-ccc

But get error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:purge-local-repository (default-cli): Goal requires a project to execute but there is no POM in this directory (...). Please verify you invoked Maven from the correct directory. -> [Help 1]

Then I create pom.xml with data:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <groupId>bbb</groupId>
  <artifactId>ccc</artifactId>
  <version>1.0</version>
  <modelVersion>4.0.0</modelVersion>
  <packaging>jar</packaging>

  <properties> 
    <groupId>${project.groupId}</groupId>
    <artifactId>${project.artifactId}</artifactId>
    <version>${project.version}</version>
    <packaging>${project.packaging}</packaging>
    <file>aaa.jar</file>
  </properties>     
</project> 

Now I can remove jar from repository. But can I remove by command line without creating pom.xml?

I'm using 3.2.5 (windows x64).

like image 210
Yura Shinkarev Avatar asked Feb 07 '23 08:02

Yura Shinkarev


2 Answers

The dependency:purge-local-repository goal, up to the current version 2.10, needs to be executed on a Maven project:

Requires a Maven project to be executed.

One of the purpose of this goal is to remove from the local repository the dependencies of a Maven project, so it needs one to execute. This explains the error you have.

However, with this plugin, it is possible to specify a manualInclude parameter, which will remove any dependency specified as groupId:artifactId:version or all versions of groupId:artifactId or even everything under a groupId. Therefore, the plugin could be updated to not require a Maven project to be executed.

I went ahead, created the JIRA issue MDEP-537 to track this addition and will fix this for version 3.0.0.

like image 193
Tunaki Avatar answered Feb 15 '23 13:02

Tunaki


As Tunaki mentioned in his answer, he requested MDEP-537 for the Dependency plugin to be able to purge without a Maven project. This has been implemented since version 3.0.0.

If you only run mvn dependency:purge-local-repository, you are likely to run an older version. E. g. my Maven 3.6.0 comes with Dependency plugin version 2.8.0.

So you should run a specific version of the plugin:

mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:purge-local-repository -DmanualInclude=...
like image 40
Peter Wippermann Avatar answered Feb 15 '23 15:02

Peter Wippermann