其實我正在使用Maven插件並創建自己的Maven插件。Maven Mojo未知生命週期階段
首先我跟着本教程:http://maven.apache.org/guides/plugin/guide-java-plugin-development.html但我意識到,這不是工作了原因不知何故"org.apache.maven.plugins.annotations.Mojo"
不存在!
之後,我發現它現在應該如何工作。爲此,我創建了這個類:
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
/**
* @goal hello
* @requiresProject false
*/
public class MyMojo extends AbstractMojo {
/**
* message to print
*
* @parameter property="hello.message" default-value="Hallo World!"
*/
private String message = "";
/**
*
*/
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info(message);
}
}
我的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>de.sample.plugin</groupId>
<artifactId>hello-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>hello-maven-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.7</compilerVersion>
<target>1.7</target>
<source>1.7</source>
</configuration>
</plugin>
</plugins>
</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>
</dependency>
</dependencies>
</project>
所以現在我的運行與MVN de.sample.plugin插件:你好,Maven的插件:0.0.1 -SNAPSHOT:你好 工作正常。但使用此:mvn de.sample.plugin:hello-maven-plugin:0.0.1-SNAPSHOT:hello hello.message="Test"
導致此錯誤:
未知生命週期階段"hello.message=Test"
。你必須指定一個有效的lifecylce階段或目標的格式........
但它應該工作?有人可以幫忙嗎?
首先,你應該這樣定義的屬性:** MVN de.sample.plugin:你好,Maven的插件:0.0。 1-SNAPSHOT:hello -Dhello.message =「Test」**「-D ...」很重要。 – khmarbaise 2013-05-11 12:01:40
「無法解析mojo de.sample.plugin的配置:hello-maven-plugin:0.0.1-SNAPSHOT:迴歸:無法在de.sample.plugin.hello-maven-plugin.mojos中找到setter,addder和field。 MyMojo for'hello.message' – user1882812 2013-05-11 12:27:29
註解不起作用,因爲您沒有使用最新版本,也沒有註釋部分參見[here](http://maven.apache.org/plugin-tools/ maven-plugin-tools-annotations/index.html)和[這裏]的東西(http://maven.apache.org/plugin-tools/maven-plugin-plugin/examples/using-annotations.html) – khmarbaise 2013-05-11 14:43:43