【问题标题】:Why does eclipse not resolve the maven plugin dependencies after it being added to the dependencies section?为什么eclipse在添加到依赖部分后不解析maven插件依赖?
【发布时间】:2012-09-17 00:04:38
【问题描述】:

我刚刚安装了 maven eclipse 插件,一切都很好。我已经尝试过创建我的第一个 mojo。设置完成后,它已经下载了所有必需的依赖项。

现在困扰我的是 Eclipse 无法解析 org.apache.maven.plugins 类。

我的 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>com.blah.dalm.mojo</groupId>
  <artifactId>assembly-mojo</artifactId>
  <packaging>maven-plugin</packaging>
  <name>Assembly Mojo</name>
  <version>0.0.1-SNAPSHOT</version>

  <build>       
    <sourceDirectory>${basedir}</sourceDirectory>
    <!-- Plugin Configurations -->
    <plugins>
        <!-- Compiler plugin to use 1.6 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <executions>
                <execution>
                </execution>
            </executions>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>

        </plugin>
    </plugins>
  </build>
  <!--  Dependencies  -->  
  <dependencies>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-plugin-api</artifactId>
        <version>2.0</version>
    </dependency>
  </dependencies>
</project>

我的 mojo 文件 AssemblyMojo.java:

package com.blah.dalm.mojo;

import java.util.List;
import org.apache.maven.plugin.MojoExecutionException; // <-- This is where it says it cannot resolve the class or package.

/**
 * "Assemble Goal"
 * @goal assemble-goal
 * @author Husain Khambaty
 *
 */
public class AssemblyMojo { 
    /**
     * @parameter expression="${assembly.sourcePath}"
     * @required
     */
    private String sourcePath;

    /**
     * @parameter expression="${assembly.outputPath}"
     * @required
     */
    private String outputFilePath;

    /**
     * @parameter
     */

    private List<String> excludeList;
    /**
     * @parameter
     */

    private String filterRule;

    public void execute() throws MojoExecutionException { // <-- And here

    }
}

它无法解析 MojoExectionException 类(因此我认为它无法找到所需的 jar,我猜它应该在 Eclipse-Maven 集成后自动获取)。

当我构建它时,它构建得很好。

【问题讨论】:

  • 当你说它构建得很好时,你是使用 maven 还是 Eclipse 构建的?我看不到任何特定于任何可能具有 MojoExectionException 类的 mojo jar 的依赖项。
  • 确保 maven-plugin-api.jar 已成功下载到您的 maven 本地存储库并存在于 Eclipse 项目的类路径中。
  • 谢谢@yorkw,您的回答让我找到了解决方案。我已将答案与我期望的工作解决方案一起放在下面。谢谢老兄。

标签: eclipse maven maven-eclipse-plugin


【解决方案1】:

解决方案:

感谢@yorkw - 他的回答让我找到了解决方案。

安装 Maven-Eclipse 插件并在 pom.xml 中添加依赖项后,它会自动从 maven 存储库中找到这些 jar,并将它们添加到“Maven 依赖项”部分。当我这样做时并没有发生这种情况(可能做错了什么)。

@yorkw 回答后,我添加了 jar 并且它起作用了。就在那时我想我已经启用了依赖项。所以只是为了它,我禁用它们并再次启用它们,突然出现“Maven Dependenices”的地方。唷。

(注意:我确实尝试过提供屏幕截图 - 但我是 StackOverflow 上的新手,它还不允许我发布图片。我会及时编辑这篇文章并为其他人提供屏幕截图)。

【讨论】:

    猜你喜欢
    • 2012-11-28
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2012-01-20
    • 1970-01-01
    • 2021-09-19
    相关资源
    最近更新 更多