I ran into this mysterious error message while trying to execute a simple Maven Mojo. I call it mysterious because of the fact that the almighty Google couldn’t help me any further on this. Here’s the build log output I had to deal with.

Nicks-MacBook-Pro:trunk Nick$ mvn compile
[INFO] Scanning for projects...
[ERROR] Failed to execute goal com.contribute:apex-maven-plugin:1.0:myMojo
(my-mojo) on project my-project: A type incompatibility occured while
executing com.contribute:apex-maven-plugin:1.0:myMojo:
com.contribute.MyMojo cannot be cast to org.apache.maven.plugin.Mojo
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>com.contribute:apex-maven-plugin:1.0
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/Nick/.m2/repository/com/contribute/apex-maven-plugin/1.0/apex-maven-plugin-1.0.jar
[ERROR] urls[1] = file:/Users/Nick/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]

Maven wasn’t able to cast my Mojo class to org.apache.maven.plugin.Mojo. I thought it had something to do with missing or corrupt dependencies, but that was just thinking too far away. I simply forgot to extend my Java class with the AbstractMojo class.

public class MyMojo extends AbstractMojo {

That fixed the type incompatibility error. Nothing less, nothing more. I hope I saved someone’s time by posting this. ;]