2

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.

maba
  • 47,113
  • 10
  • 108
  • 118
Husain Khambaty
  • 740
  • 1
  • 9
  • 22
  • When you say it builds just fine, are you building using maven or Eclipse? I cannot see any dependency added specific to any mojo jar which might have the MojoExectionException class. – Metalhead Sep 25 '12 at 13:20
  • Make sure maven-plugin-api.jar has successcully downoladed in your maven local repository and exist in classpath in Eclipse project. – yorkw Sep 25 '12 at 21:27
  • Thank you @yorkw, your answer led me to the solution. I have put the answer below along with the working solution that I was expecting. Thanks mate. – Husain Khambaty Sep 26 '12 at 05:17

1 Answers1

0

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).

Husain Khambaty
  • 740
  • 1
  • 9
  • 22