我已遵循本指南:
http://maven.apache.org/guides/plugin/guide-java-plugin-development.html
我用 pom 文件创建了一个 maven-plugin 项目“hello-maven-plugin”:
<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>
当我构建它时:
mvn install
它打印“你好,世界”。按预期在控制台中。
我创建了另一个 maven 项目“my-project-usage”,我想在其中使用“hello-maven-plugin”插件。它有这个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>
当我构建这个项目时,hello-maven-plugin 永远不会执行,为什么?