0

I have written a custom plugin, then I installed it. Then I modified the pom.xml of the project from which I want to use the custom plugin. When I invoke my plugin goal directly the plugin goal is executed successfully, but when I try to mvn compile my custom plugin goal is not executed. What might be the reason?

My plugin's 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.xxx.plugins.maven</groupId>
  <artifactId>datanucleus-enhance-maven-plugin</artifactId>
  <packaging>maven-plugin</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>Datanucleus-enhance Maven Plugin</name>
  <dependencies>
    <dependency>
      <groupId>org.apache.maven.plugin-tools</groupId>
      <artifactId>maven-plugin-annotations</artifactId>
      <version>3.2</version>
    </dependency>
    <dependency>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-plugin-api</artifactId>
      <version>2.0</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

My project using custom plugin I added following:

    <!-- enhance JDO classes -->
    <plugin>
      <groupId>com.sukantu.plugins.maven</groupId>
      <artifactId>datanucleus-enhance-maven-plugin</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <configuration>
        <jdoClassDirList>
          <param>target/${project.artifactId}-${project.version}/WEB-INF/classes/</param>
        </jdoClassDirList>
        </configuration>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>enhance</goal>
            </goals>
          </execution>
        </executions>
    </plugin>

I followed section Attaching the Mojo to the Build Lifecycle from maven guide site: https://maven.apache.org/guides/plugin/guide-java-plugin-development.html

The following command successfully calls my plugin goal: mvn com.xxx.plugins.maven:datanucleus-enhance-maven-plugin:enhance

The following command does NOT successfully call my plugin goal: mvn compile

Thanks for any inputs!

Stefan Ferstl
  • 5,135
  • 3
  • 33
  • 41
CoolDude
  • 417
  • 1
  • 5
  • 11

1 Answers1

2

I came across this link: How do I link a plugin execution to a phase in maven without forcing me to specify plugin on command line

So I removed <pluginManagement> tags so <plugins> appear directly under '<build>'. Then I tried 'mvn compile' from command line and it successfully called my custom plugin goal!

But when I checked pom.xml in Eclipse I saw another error referenced here How to solve “Plugin execution not covered by lifecycle configuration” .

Since the command line is working correctly, I think this is m2e Eclipse plugin error and so I have disabled the marked by going to 'Eclipse' -> 'Window' -> 'Show View' -> 'Markers' -> right click that marker -> 'Delete'. Now Eclipse is not showing any error and command line is also working as expected. Hope this helps someone else.

Community
  • 1
  • 1
CoolDude
  • 417
  • 1
  • 5
  • 11