Maven目标提出“未找到所需目标”

时间:2010-09-24 15:19:31

标签: maven-2 maven-plugin

我正在尝试生成maven插件,如the maven documentation中所述。

所以我用Eclipse创建了一个新的插件项目,使用mvn archetype:

<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>com.test</groupId>
  <artifactId>hotdeploy</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>maven-plugin</packaging>
  <description>Maven Plugin to hotdeploy portlets to server</description>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.2.1</version>
    </dependency>
  </dependencies>
</project>

我使用了创建的java类文件:

package com.test.mavenplugins;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;

/**
 * Hot Deploy something components to local server.
 * @goal hotdeploy
 */
public class HotDeployMojo extends AbstractMojo {
     public void execute() throws MojoExecutionException
        {
            getLog().info("Hello, world.");
        }
}

并且没有错误地运行mvn install。然后我将这个插件包含在另一个项目中:

  <build>
    <plugins>
      <plugin>
        <groupId>com.test</groupId>
        <artifactId>hotdeploy</artifactId>
        <version>0.0.1-SNAPSHOT</version>
      </plugin>
    </plugins>
  </build>

但是当我致电mvn com.test:hotdeploy:hotdeploy时,我收到以下错误:

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Required goal not found: com.test:hotdeploy:hotdeploy in com.test:hotdeploy:0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------

有人可以帮我解决这个错误吗?

1 个答案:

答案 0 :(得分:0)

传递版本时工作:

$ mvn com.test:hotdeploy:0.0.1-SNAPSHOT:hotdeploy
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building hotdeploy 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- hotdeploy:0.0.1-SNAPSHOT:hotdeploy (default-cli) @ hotdeploy ---
[INFO] Hello, world.
[INFO] ------------------------------------------------------------------------
...

顺便说一下,我建议遵循artifactId的maven-$name-plugin$name-maven-plugin命名约定。

以防万一,您可能还想阅读: