1

I would need to execute a specific Maven plugin from command line. For example, in the following I execute a specific version of Maven Surefire Plugin to test Java projects:

mvn org.apache.maven.plugins:maven-surefire-plugin:2.19-SNAPSHOT:test

However, the above assumes to find the surefire plugin 2.19 in the default Maven repository path. Now, my question is, if I want to use the plugin with a specific path (not Maven default one), what should I do using the command line? I would expect something like the following, without modifying pom.xml:

mvn /path/to/some/jar/version/org.apache.maven.plugins:maven-surefire-plugin:2.19-SNAPSHOT:test

or more generally, for the following invocation

mvn groupId:artifactId:version:goal

I would need somewhere to specify a customized path to execute its goal

mvn /some/path/to/groupId:artifactId:version:goal

On the other hand, please let me know if this is not even supported by Maven.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Bruce
  • 1,608
  • 2
  • 17
  • 29

1 Answers1

3

This is not how it works. Maven will always look-up artifacts inside your local repository. And if it can't find it in your local repository, it will try to download it from configured remote repositories.

As such, you don't specify a path to a plugin. You specify a path to a local repository, where that plugin is installed. In this local repository will be installed all the dependencies of the plugin you're trying to invoke. This also means that you cannot have a JAR to a plugin "sitting around" anywhere; it needs to be located inside a correct repository tree directory. With a local repository of /my/local/repo, the artifacts of the plugin groupId:artifactId:version must be located in /my/local/repo/groupId/artifactId/version and be named artifactId-version.jar (and .pom). In the same say, the location of the dependencies of that plugin must follow that directory structure.

By default, the local repository is located inside ~/.m2/repository. But you can change that by:

  1. Specifying the maven.repo.local system property on the command line, for example with mvn -Dmaven.repo.local=/path/to/local/repo groupId:artifactId:version:goal;
  2. Use a custom settings.xml and tell Maven to use it with the -s command line option. It would contain:

    <settings>
      <localRepository>/path/to/local/repo</localRepository>
    </settings>
    

    and be used with mvn -s /path/to/settings.xml groupId:artifactId:version:goal

Community
  • 1
  • 1
Tunaki
  • 132,869
  • 46
  • 340
  • 423