【问题标题】:Maven goal raises "Required goal not found"Maven 目标引发“未找到所需目标”
【发布时间】:2010-09-24 15:19:30
【问题描述】:

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

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

<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] ------------------------------------------------------------------------

谁能帮我解决这个错误?

【问题讨论】:

    标签: maven-2 maven-plugin


    【解决方案1】:

    通过版本时有效:

    $ mvn com.test:hotdeploy:0.0.1-SNAPSHOT:hotdeploy [INFO] 正在扫描项目... [信息] [信息] --------------------------------------------- ------------------------- [INFO] 构建 hotdeploy 0.0.1-SNAPSHOT [信息] --------------------------------------------- ------------------------- [信息] [信息] --- hotdeploy:0.0.1-SNAPSHOT:hotdeploy (default-cli) @ hotdeploy --- [信息] 你好,世界。 [信息] --------------------------------------------- ------------------------- ...

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

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

    【讨论】:

    • 对不起,它对我不起作用,我仍然得到同样的错误:“找不到所需的目标:com.test:hotdeploy:0.0.1-SNAPSHOT:hotdeploy in com.test:hotdeploy: 0.0.1-SNAPSHOT"
    • 感谢您的尝试。我也阅读了链接中的描述,但仍然没有成功。我也想不通,为什么它找不到目标。
    猜你喜欢
    • 2011-05-04
    • 2019-01-17
    • 2021-03-07
    • 2023-04-05
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-11
    相关资源
    最近更新 更多