I'm using a a basic maven project where only the following things are defined in pom.xml:
Why can I run mvn checkstyle:checkstyle
in the command window? Shouldn't I have to define the checkstyle plugin the pom.xml
? What am I missing?
Edit: The eclipse plugin "Eclipse Checkstyle Plug-In" is installed. Is that the reason? If yes, how does maven communicate with it?
To generate the Checkstyle report as part of the Project Reports, add the Checkstyle Plugin in the <reporting> section of your pom. xml . Then, execute the site phase to generate the report.
Checkstyle obtains a configuration from an XML document whose elements specify the configuration's hierarchy of modules and their properties. You provide a file that contains the configuration document when you invoke Checkstyle at the command line, and when you run a Checkstyle task in ant.
Go to Settings|Editor|Code Style, choose a code style you want to import CheckStyle configuration to. Click on the gear, then 'import scheme', choose "CheckStyle Configuration" and select a corresponding CheckStyle configuration file. Click OK.
As you have already seen it is possible to execute plugins directly from the command line without configuring the plugin in your project's POM file.
To know which plugin you want to execute maven uses plugin prefix resolution.
Using your command line, mvn checkstyle:checkstyle
, as an example this is roughly what maven does:
checkstyle
.maven-${prefix}-plugin
(for official Maven plugins)${prefix}-maven-plugin
(for plugins from other sources)maven-checkstyle-plugin
as the artifactId of the pluginorg.apache.maven.plugins
)All of this is explained in far more detail and better than I can at the plugin prefix mapping page of the official maven documentation.
The reason is that a plugin might not need to be explicitly configured in the pom nor to be bound to a phase to be run. And so, it can always be run by direct invocation (specifying the goal instead the phase when invoking to Maven):
mvn [options] [<goal(s)>] [<phase(s)>]
Look at the lifecycle documentation:
A plugin goal represents a specific task (finer than a build phase) which contributes to the building and managing of a project. It may be bound to zero or more build phases. A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation.
It definitely has nothing to be with Eclipse plugins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With