I have followed this guide:
http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
I have created a maven-plugin project “hello-maven-plugin” with the pom file:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Sample Parameter-less Maven Plugin</name>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>sayhi</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
and when I build it with:
mvn install
it prints “Hello, world.” in the console as expected.
I have created another maven project “my-project-usage” where I would like to use the “hello-maven-plugin” plugin. It has this pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>my-project</artifactId>
<groupId>com</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>my-project-usage</artifactId>
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>
When I build this project the hello-maven-plugin is never executed, why?
Move this
<execution>block from first POM to then second one, because you need plugin’s execution there, where you use the plugin, not in the plugin itself.