微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Maven pom.xml 中的插件是否需要 groupId?

如何解决Maven pom.xml 中的插件是否需要 groupId?

在我的 pom.xml 中,如果我给出以下内容,它似乎可以工作。

      <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
      </plugin>

插件不需要 groupId 吗? 如果没有给出groupId,maven如何下载插件

谢谢

解决方法

在 pom.xml 中,您可以通过 groupId、artifactId 和 version 定义插件。但是对于 groupId,在 Maven 4.0.0 XSD file 中定义了一个默认值。如果您查看插件的定义(这里是 XSD 文件的摘录):

<xs:complexType name="Plugin">
<xs:annotation>
<xs:documentation source="version">4.0.0+</xs:documentation>
<xs:documentation source="description"> The <code>&lt;plugin&gt;</code> element contains informations required for a plugin. </xs:documentation>
</xs:annotation>
<xs:all>
<xs:element minOccurs="0" name="groupId" type="xs:string" default="org.apache.maven.plugins">
<xs:annotation>
<xs:documentation source="version">4.0.0+</xs:documentation>
<xs:documentation source="description">The group ID of the plugin in the repository.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="artifactId" type="xs:string">
<xs:annotation>
<xs:documentation source="version">4.0.0+</xs:documentation>
<xs:documentation source="description">The artifact ID of the plugin in the repository.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="version" type="xs:string">
<xs:annotation>
<xs:documentation source="version">4.0.0+</xs:documentation>
<xs:documentation source="description">The version (or valid range of versions) of the plugin to be used.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" name="extensions" type="xs:string

您可以看到,为 groupId 定义了默认值 org.apache.maven.pugins。这意味着每次您未在区域 pluginReportPlugin 中定义 groupId 时,它都会自动使用 groupId。 org.apache.maven.plugins为此。

mentioned search for plugins is something different。这是从命令链接调用插件目标的情况,如下所示:

mvn versions:set ...
mvn help:help ...

默认情况下,将在两个 groupId 中搜索给定名称:org.apache.maven.pluginsorg.codehaus.mojo。插件本身的名称是根据两种命名模式 maven-${prefix}-plugin 搜索的,这适用于在 Apache 软件基金会中开发的所有 Maven 插件(including the trade mark of the ASF 与该命名空间相关,还包括 groupId)和第二个命名模式 ${prefix}-maven-plugin

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。