How does maven knows which plugin needs to invoke from the goal?

Viewed 144

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'?

1 Answers

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 )
Related