我有一个使用pom.xml中Maven2的绑定到一个自定义
<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>pram.plugintest</groupId>
<artifactId>pram.plugintest</artifactId>
<packaging>maven-plugin</packaging>
<version>1.1-SNAPSHOT</version>
<name>pram.plugintest Maven Mojo</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.3</version>
<configuration>
<goalPrefix>blah</goalPrefix>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
<dependencies>
<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>
定义运行
mvn blah:touch
创建在目标目录中的一个文本文件,如预期的那样自定义插件。我现在建立在POM
<lifecycles>
<lifecycle>
<id>touch</id>
<phases>
<phase>
<id>package</id>
<executions>
<execution>
<goals>
<goal>touch</goal>
</goals>
</execution>
</executions>
</phase>
</phases>
</lifecycle>
</lifecycles>
在另一个Maven项目指定的资源目录中的文件lifecycles.xml,我想的mvn blah:touch
运行绑定到与此类似
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>test1</id>
<phase>blah:touch</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
</configuration>
</execution>
</executions>
</plugin>
...
执行任务
但是,运行此操作会创建文本文件,但不会尝试运行org.sonatype.mavenbook.weather.Main
这是正确的方法吗?
最终我想在exec-maven-plugin中有多个执行部分没有绑定到默认阶段。从逻辑上讲它应该是这样的
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>test1</id>
<phase>blah:touch</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.Main</mainClass>
</configuration>
</execution>
<execution>
<id>test2</id>
<phase>blah:touch2</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>mainClass=org.sonatype.mavenbook.weather.SomeOtherClass</mainClass>
</configuration>
</execution>
</executions>
</plugin>
...
所以,如果我跑mvn blah:touch
然后org.sonatype.mavenbook.weather.Main
将被执行,如果我跑mvn blah:touch2
然后org.sonatype.mavenbook.weather.SomeOtherClass
将转而执行。
它似乎应该是直接做,但在documentation似乎没有指出如何做到这一点。
我想实现的是将exec-maven-plugin中的不同执行部分链接到非默认阶段。我将在原文中对此进行扩展 – Pram 2012-03-13 16:00:58