我写了一个自定义插件,然后我安装了它。然后我修改了我想使用自定义插件的项目的pom.xml
。当我直接调用我的插件目标时,插件目标成功执行,但是当我尝试mvn compile
我的自定义插件目标未被执行时。可能是什么原因?Maven默认编译没有选择自定义插件目标
我插件的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>
我跟着段从行家指南网站装上的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,但后来发现如何解决此问题。请参阅我发布的答案。谢谢。 – CoolDude