user983447
user983447

Reputation: 1727

How does Maven identify plugins without group ID on the command line?

With Maven, I can run a command like this from the command line and it works:

mvn compiler:compile

How does Maven know which plugin I want to use, even though I did not provide a group ID?

Upvotes: 7

Views: 861

Answers (1)

whitlaaa
whitlaaa

Reputation: 922

Maven plugins typically follow one of two naming conventions:

  • ${name}-maven-plugin
  • maven-${name}-plugin (reserved for Apache Maven project plugins)

Plugins that follow one of the conventions, such as the maven-compiler-plugin or the wildfly-maven-plugin, can be used via their shortened version on the command line; compiler or wildfly. This makes it so you don't need to provide the fully qualified groupId:artifactId:version:command form.

You could absolutely do something like:

mvn org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile to use its fully qualified name, but obviously the shortened form is much easier to work with.

There are a handful of other ways to provide shortened forms. The plugin development guide gives some good detail on this, specifically paragraph "shortening the command line".


Update by kriegaex: Maven also by default seems to only search group IDs org.apache.maven.plugins and org.codehaus.mojo, so if you run something like

mvn buildplan:list-phase

the result will be

[ERROR] No plugin found for prefix 'buildplan' in the current project and
        in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo]
        available from the repositories

If you want more comfort on the command line, i.e. not specify the group ID fr.jcgay.maven.plugins in this case, add this to ~/.m2/settings.xml:

<pluginGroups>
  <pluginGroup>fr.jcgay.maven.plugins</pluginGroup>
</pluginGroups>

Upvotes: 8

Related Questions