Let's say
when you call mvn archetype:generate
how does maven knows that it needs to invoke "Maven Archetype Plugin"?
Or when you do mvn dependency:copy-dependencies
how does it invoke 'Apache Maven Dependency Plugin'?
i.e How does maven maintains the link between 'archetype' -> 'Maven Archetype Plugin'?
Plugins are the central feature of Maven that allow for the reuse of common build logic across multiple projects. They do this by executing an "action" (i.e. creating a WAR file or compiling unit tests) in the context of a project's description - the Project Object Model (POM).
Maven exec plugin allows us to execute system and Java programs from the maven command. There are two goals of the maven exec plugin: exec:exec - can be used to execute any program in a separate process.
If you want to run the unit tests, run test . This command executes each default lifecycle phase in order ( validate , compile , package , etc.), before executing verify .
It's available by default. This page lists the core plugins and others
https://maven.apache.org/plugins/.
If you want to use other plugin, you need to mention in pom.xml file, so that the dependencies can be resolved.
<build>
<plugins>
<!--Restdocs config for collating all snippets start-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>XXX</version>
...
</plugin>
</plugins>
</build>
If you run the command mvn animal-sniffer:check
. animal-sniffer
is the plugin prefix and check
is the goal. The mapping between prefix and dependency is mentioned here. Meanwhile, the goal check
is mapped by annotation in actual implementation, if you check the source code of this plugin, you will see something like below.
@Mojo( name = "check", defaultPhase = LifecyclePhase.PROCESS_CLASSES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true )
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