Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

maven

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

like image 843
Yans Avatar asked Sep 19 '18 11:09

Yans


People also ask

How do plugins work in Maven?

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

Which plugin is used to execute the project?

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.

Which of the following Maven command makes sure that all lifecycle methods are called?

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 .


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 )
like image 104
sayboras Avatar answered Oct 13 '22 10:10

sayboras