【发布时间】:2014-03-30 16:48:11
【问题描述】:
我写了一个自定义插件,然后我安装了它。然后我修改了我想使用自定义插件的项目的pom.xml。当我直接调用我的插件目标时,插件目标成功执行,但是当我尝试mvn compile 时,我的自定义插件目标没有执行。可能是什么原因?
我的插件pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xxx.plugins.maven</groupId>
<artifactId>datanucleus-enhance-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>Datanucleus-enhance Maven Plugin</name>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
我使用自定义插件的项目我添加了以下内容:
<!-- enhance JDO classes -->
<plugin>
<groupId>com.sukantu.plugins.maven</groupId>
<artifactId>datanucleus-enhance-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<configuration>
<jdoClassDirList>
<param>target/${project.artifactId}-${project.version}/WEB-INF/classes/</param>
</jdoClassDirList>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
我遵循了 maven 指南站点中的 将 Mojo 附加到构建生命周期部分:https://maven.apache.org/guides/plugin/guide-java-plugin-development.html
以下命令成功调用了我的插件目标:
mvn com.xxx.plugins.maven:datanucleus-enhance-maven-plugin:enhance
以下命令未成功调用我的插件目标:
mvn compile
感谢您的任何意见!
【问题讨论】:
-
你在哪里定义的插件配置?
/ 或 / ? -
我之前尝试使用 pluginManagement,但后来发现如何解决此问题。请参阅我发布的答案。谢谢。
标签: maven-plugin