Maven: Why can I run mvn checkstyle: checkstyle without pom.xml config?

I am using a basic maven project where only the following things are defined in pom.xml:

  • javaee-api dependency
  • junit dependency
  • maven-compile-plugin
  • maven-war-plugin
  • wildfly-maven-plugin

Why can I run mvn checkstyle:checkstyle in the command window? Should I define the checkstyle pom.xml ? What am I missing?

Edit: The eclipse plug-in "Eclipse Checkstyle Plug-In" is installed. This is the reason? If so, how to communicate with him?

+5
source share
2 answers

As you have already seen, it is possible to execute plugins directly from the command line without configuring the plugin in the project POM file.

To find out which plugin you want to execute, maven uses plugin prefix permission.

Using your mvn checkstyle:checkstyle command line mvn checkstyle:checkstyle , as an example, this is roughly what maven does:

  • take the prefix, the bit before the colon, from the execution. In your case, checkstyle .
  • allow this possible name (artifactId) of the plugin. To do this, it uses two possible formats:
    • maven-${prefix}-plugin (for official Maven plugins)
    • ${prefix}-maven-plugin (for plugins from other sources)
  • now it has maven-checkstyle-plugin as artifactId plugin
  • find the plugin with this artifactId and one of the configured groupIds ids (by default, maven searches with groupId org.apache.maven.plugins )
  • he finds maven-checkstyle-plugin
  • fulfills the goal (the bit after the colon in the command), so the goal of the click in this case.

All this is explained in much more detail and better than I can on the prefix prefix page of the maven official documentation plugin .

+12
source

The reason is that the plugin may not have to be explicitly configured in pom or is not related to the phase that needs to be run. And therefore, it can always be controlled by a direct call (indicating a target instead of a phase when calling Maven):

 mvn [options] [<goal(s)>] [<phase(s)>] 

Check out the lifecycle documentation:

The purpose of the plugin is a specific task (more subtle than the build phase), which contributes to the creation and management of the project. It may be associated with zero or more assembly phases. A target that is not associated with any phase of the assembly can be performed outside the assembly life cycle by a direct call.

This definitely has nothing to do with Eclipse plugins.

0
source

Source: https://habr.com/ru/post/1236965/


All Articles