Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

is groupId required for plugins in Maven pom.xml?

In my pom.xml if I give the following, it seems to work.

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

is groupId not required for plugins? If groupId is not given, how does maven download the plugin?

Thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the pom.xml you can define a plugin via groupId, artifactId and version. But for the groupId there is defined a default value in the Maven 4.0.0 XSD file. If you take a look at the definition for plugins (here an excerpt from the XSD file):

<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

There you can see that for the groupId a default value org.apache.maven.pugins is defined. That means every time you do not define a groupId in the areas plugin and ReportPlugin it will automatically using the groupId. org.apache.maven.plugins for this.

The mentioned search for plugins is something different. This is the case for calling a plugin goal from command linke like the following:

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

by default the given names will be search in two groupId's: org.apache.maven.plugins and org.codehaus.mojo. The name of the plugin itself is searched based on two naming patterns maven-${prefix}-plugin which is the case for all Maven plugins which are developed in the Apache Software Foundation (including the trade mark of the ASF related to that namespace which also includes the groupId) and the second naming pattern ${prefix}-maven-plugin.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...