自动执行自定义Maven插件

时间:2012-12-31 11:46:38

标签: java maven-2 maven-plugin

我已经实现了一个Maven 2插件。

我对我的Mojo有定义:

/**
 * Goal which combines files.
 *
 * @goal combine
 * @phase compile
 */
public class CombineMojo extends AbstractMojo {

我必须将它添加到我的项目中(使用插件)pom:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <groupId>base-project</groupId>
    <artifactId>base-project</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>combine-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <input>src/input.html</input>
                    <output>html/output.html</output>
                </configuration>
                <executions>
                    <execution>
                        <id>combine-maven-plugin</id>
                        <goals>
                            <goal>combine</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

但是我该怎么做才能自动执行它而不是在pom.xml中定义它。我尝试添加

@execute ...

进入我的Mojo定义然而它没有用。顺便说一句,我应该定义一个id,它需要什么?

1 个答案:

答案 0 :(得分:0)

maven插件只有在Maven中绑定life-cycle phase时才能执行。