Why does eclipse not resolve the maven plugin dependencies after it being added to the dependencies section?

StackOverflow https://stackoverflow.com/questions/12583504

Question

I just installed the maven eclipse plugin and all is great. I have tried creating my first mojo. After the setup, it has downloaded all the required dependencies.

Now what is troubling me is that Eclipse isn't able to resolve the org.apache.maven.plugins classes.

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

My mojo file 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

    }
}

It is unable to resolve the MojoExectionException class (therefore I believe it isn't able to find the rerquired jars, which I guess it is supposed to automatically fetch after the Eclipse-Maven integration).

When I build it, it builds just fine.

Was it helpful?

Solution

Solution :

Thanks to @yorkw - his answer led me to the solution.

After installing the Maven-Eclipse plugin, and adding the dependencies in the pom.xml, it is automatically supposed to find those jars from the maven repository and add them in a "Maven Dependencies" section. This didn't happen when I did it (probably did something wrong).

After @yorkw answer, I added the jar and it worked. Just then I figured that I had already enabled the Dependencies. So just for the heck of it, I disabled them and enabled them again and suddenly out of no where the "Maven Dependenices" appeared. Phew.

(Note : I did try putting up screenshots - but I'm a newbie on StackOverflow and it wont allow me to post images yet.. I shall in time edit this post back and put the screen shots for others).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top