在打包之前,我不明白如何在 Maven 中运行任务。
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks>
<echo message="****** TEST *****" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
当我运行时mvn clean package
,它不会被执行。我怎样才能执行这个任务?如果重要的话,我正在使用 maven 3.0.5。
** 更新: **
添加id
并goal
按照建议,从命令行解决了问题。
<id>my-generate-sources</id>
<goals>
<goal>run</goal>
</goals>
为了修复 Eclipse 错误,我在构建部分配置了 lifecyleMappingMetadata:
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<versionRange>[1.7,)</versionRange>
<goals>
<goal>run</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>