java - maven 插件别名是如何映射的

标签 java maven maven-3

我正在尝试了解 mvn clean:clean 实际上做了什么。

mvn -B help:describe -Dcmd=clean
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample-one 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ sample-one ---
[INFO] 'clean' is a lifecycle with the following phases:
* pre-clean: Not defined
* clean: org.apache.maven.plugins:maven-clean-plugin:2.5:clean
* post-clean: Not defined

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.689 s
[INFO] Finished at: 2015-12-10T10:20:16-08:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------

在我看来,mvn clean:cleanmvn org.apache.maven.plugins:maven-clean-plugin:2.5:clean 相同。因此我假设 mvn clean:clean 中的第一个 clean 只是 org.apache.maven.plugins:maven-clean-plugin:2.5< 的别名。类似地,mvn maven-surefire-plugin:2.12.4:testmvn surefire:test 相同。

所以不知何故,maven-surefire-plugin:2.12.4 似乎指的是 surefireorg.apache.maven.plugins:maven-clean- plugin:2.5clean

当我查看 effective-pom 时,我看到以下内容 maven-surefire-插件 2.12.4 默认测试 测试 测试 maven-clean-插件 2.5 默认清理 干净的 干净的

如您所见,pom 似乎没有定义别名。下面是我的问题

  1. 我对插件别名的理解是否正确
  2. 如果我对别名的理解是正确的 - a) 它们是如何定义的,在哪里定义的? b) 有没有办法列出所有别名。

最佳答案

来自关于 plugins development 的官方 Maven 文档:

Shortening the Command Line
There are several ways to reduce the amount of required typing:

  • If you need to run the latest version of a plugin installed in your local repository, you can omit its version number. So just use mvn sample.plugin:hello-maven-plugin:sayhi to run your plugin.
  • You can assign a shortened prefix to your plugin, such as mvn hello:sayhi. This is done automatically if you follow the convention of using ${prefix}-maven-plugin (or maven-${prefix}-plugin if the plugin is part of the Apache Maven project). You may also assign one through additional configuration - for more information see Introduction to Plugin Prefix Mapping.
  • Finally, you can also add your plugin's groupId to the list of groupIds searched by default. To do this, you need to add the following to your ${user.home}/.m2/settings.xml file:

    <pluginGroups> <pluginGroup>sample.plugin</pluginGroup>
    </pluginGroups>

At this point, you can run the mojo with mvn hello:sayhi.

因此,别名不是在 pom 文件中定义的,而是 maven 内置机制的一部分。有关 Plugin Prefix Resolution 的官方文档中还提供了更多详细信息.

关于java - maven 插件别名是如何映射的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34211805/

相关文章:

java - 如何使用 IntelliJ IDEA 执行 mvn 命令?

java - 如何使用maven构建spring boot应用程序的库jar

java - 如何转义 IntelliJ 文件模板中的 Maven 属性

java - Java3d 小程序中的 JPopupMenu 不接收鼠标或键盘输入

maven - EAR 的 Grails Maven 包装

maven - Java11/JavaFX 和 Maven 不会在 NetBeans IDE 9 之外运行

integration-testing - Cobertura 覆盖 Maven 中的集成测试

java - 以编程方式下载 Maven 依赖项

java - 来自命令行工具的 WADL2JAVA JClass 名称为空错误

java - Couchbase Bucket 身份验证错误