Developing and debugging Maven plugins

Starting from 0.9.2 version, Workspace dependency resolution can be enabled for Maven builds launched in external JVM and starting from version 0.9.4 this works for both embedded and external maven runtimes (tested with 2.0.8 and a recent 2.1-SNAPSHOT). This opens up some interesting possibilities for Maven plugin developers – Maven plugins can be executed directly from Workspace.

Attached to this page are two small projects that show how to develop and debug Maven plugins from Eclipse.

sampleplugin is a trivial Maven plugin with single mojo to set a project property and sampleproject uses sampleplugin to store the property value in a file. Here is relevant snippet from sampleproject/pom.xml

<plugins>
    <plugin>
      <groupId>org.maven.ide.eclipse.sample.pluginresolution</groupId>
      <artifactId>sampleplugin</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <executions>
        <execution>
          <phase>validate</phase>
          <goals>
            <goal>set-property</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>

Now open Maven build launch configuration from Run As... / Maven build... popup menu:

Type in process-resources goal, select external Maven runtime:

and run the build. The build fails, assuming sampleplugin is not installed in your local Maven repository:

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).

Project ID: org.maven.ide.eclipse.sample.pluginresolution:sampleplugin

Reason: POM 'org.maven.ide.eclipse.sample.pluginresolution:sampleplugin' 
  not found in repository: Unable to download the artifact from any repository

Now enable Workspace artifact resolution in the launch configuration and run the build again:

The build runs without errors now and /sampleproject/target/classes/application.properties contains expected value.

Known problems/limitations and workarounds

  • Maven plugin descriptor is not automatically (re)generated after java code change. Run as maven build "process-classes" for the maven plugin project as a workaround.

Labels