简体   繁体   English

使用特定路径从命令行运行特定插件的 maven

[英]Run maven with specific path to certain plugin from command line

I would need to execute a specific Maven plugin from command line.我需要从命令行执行特定的 Maven 插件。 For example, in the following I execute a specific version of Maven Surefire Plugin to test Java projects:例如,在下面我执行特定版本的 Maven Surefire Plugin 来测试 Java 项目:

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.但是,上面假设在默认的 Maven 存储库路径中找到了 surefire 插件 2.19。 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?现在,我的问题是,如果我想使用具有特定路径(不是 Maven 默认路径)的插件,我应该使用命令行做什么? I would expect something like the following, without modifying pom.xml :我希望类似以下内容,而无需修改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.另一方面,如果 Maven 甚至不支持,请告诉我。

This is not how it works.这不是它的工作原理。 Maven will always look-up artifacts inside your local repository. Maven 将始终在您的本地存储库中查找工件。 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;这也意味着您不能在任何地方“闲置”插件的 JAR; 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 ).使用/my/local/repo的本地存储库,插件groupId:artifactId:version必须位于/my/local/repo/groupId/artifactId/version并命名为artifactId-version.jar (和.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 .默认情况下,本地存储库位于~/.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 ;在命令行上指定maven.repo.local系统属性,例如使用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 .使用自定义settings.xml并告诉 Maven 使用-s命令行选项 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并与mvn -s /path/to/settings.xml groupId:artifactId:version:goal

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM