75

I am following the tutorial for creating a maven plugin and cannot run mvn install without getting errors. The info complains that i don't have the required mojo descriptors when the annotations should be generating them for me. I am running maven 3.0.5 and using intellij as my ide. here is my Main class:

@Mojo(name = "modify-connector")
public class ComplianceMojo extends AbstractMojo {

    @Parameter
    private String artifactId;

    @Parameter
    private String version;

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        File jar = new File(getPluginContext().get("project.build.directory") + "/"
                + getPluginContext().get("project.build.finalname") + "/" + artifactId + "-" + version);
        if(jar.exists()){
            getLog().info("The file exists! " + jar.getAbsolutePath());
        } else {
            getLog().info("The file does not exist: " + jar.getAbsolutePath());
        }
    }
}

And here is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>mysql-jdbc-compliance-maven-plugin</groupId>
    <artifactId>mysql-jdbc-compliance-maven-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>maven-plugin</packaging>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-plugin-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugin-tools</groupId>
            <artifactId>maven-plugin-annotations</artifactId>
            <version>3.2</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

</project>

Note: I had to separately add the annotations dependency as the main plugin api did not contain these classes. when i run mvn install on my project, the output is as follows:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.867s
[INFO] Finished at: Wed Sep 25 17:45:55 EST 2013
[INFO] Final Memory: 8M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:2.9:descriptor (default-descriptor) on project mysql-jdbc-compliance-maven-plugin: Error extracting plugin descriptor: 'No mojo definitions were found for plugin: mysql-jdbc-compliance-maven-plugin:mysql-jdbc-compliance-maven-plugin.' -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

6 Answers 6

66

Maybe this is related to a unresolved issue in Maven: https://issues.apache.org/jira/browse/MNG-5346

For my plugin projects, i could workaround by adding an explicit execution of the maven-plugin-plugin:

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-plugin-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <!-- see http://jira.codehaus.org/browse/MNG-5346 -->
                    <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
                </configuration>

                <executions>
                    <execution>
                        <id>mojo-descriptor</id>
                        <goals>
                            <goal>descriptor</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

But see the comments in the JIRA issue for more elaborate solutions!

6
  • I have read the issue you have posted and have implemented the work around on the website and it has worked! Thanks for pointing it out to me :) Sep 25, 2013 at 8:30
  • 9
    This issue has been fixed in 3.2.2: maven.apache.org/docs/3.2.2/release-notes.html Sep 5, 2014 at 2:57
  • Thank you, this solved my build issue on a machine running Maven 3.0.5
    – qqilihq
    Nov 29, 2015 at 10:31
  • 2
    Half a decade later and this solution still holds when maven-plugin-plugin crashes on maven 3.6.3. Thank you Sep 24, 2020 at 10:22
  • I can still reproduce the issue in 3.5+, but luckily this same solution still works to fix it! Thanks!
    – Matsu Q.
    Oct 19, 2020 at 16:55
41

after reading the Jira Issue that Gyro posted, i added the following lines to my pom and everything compiled nicely.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <goalPrefix>mysql-jdbc-compliance</goalPrefix>
            </configuration>
            <executions>
                <execution>
                    <id>default-descriptor</id>
                    <goals>
                        <goal>descriptor</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
                <execution>
                    <id>help-descriptor</id>
                    <goals>
                        <goal>helpmojo</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
2
  • 6
    This entry is actually added to your plugin's pom.xml automatically if you generate the project using maven archetype: mvn archetype:generate -DgroupId=com.example -DartifactId=my-awesome-maven-plugin -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-plugin
    – Jan Molak
    Jul 9, 2015 at 11:39
  • 3
    With mvn 3.3.9 I only required groupId, artifactId and v3.5 - all the config is default.
    – Adam
    Nov 2, 2017 at 9:53
38

As mentioned in the previous answer, this was a bug and it is now fixed.

You just need to tell maven it should use a newer version of the maven-plugin-plugin.

Here is what my pom file looks like:

<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/xsd/maven-4.0.0.xsd">
  <!-- ...other maven config... -->
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>3.3</version>
      </plugin>
    </plugins>
  </build>
</project>
3
16

Simply incrementing maven plugin version to 3.3 or 3.4 won't fix any issue (as some has stated).

You have to add a minimum of default-descriptor execution with the correct phase. So the minimum config of build information is as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-plugin-plugin</artifactId>
            <version>3.1</version>
            <executions>
                <execution>
                    <id>default-descriptor</id>
                    <phase>process-classes</phase>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

irrespective of maven-plugin-plugin version. (it can be 3.1, 3.2, 3.3. 3.4 (didn't test the others)).

will yield:

...
[INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ example-maven-plugin ---
[WARNING] Using platform encoding (UTF-8 actually) to read mojo metadata, i.e. build is platform dependent!
[INFO] Applying mojo extractor for language: java-annotations
[INFO] Mojo extractor for language: java-annotations found 1 mojo descriptors.
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 0 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors.
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Another option if you don't want to have build tags in your pom, you can use javadocs on your Mojo. For instance:

/**
 * @goal run123
 */
@Mojo(name = "run123")
public class MyMojo extends AbstractMojo {
}

will yield:

...
[INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ example-maven-plugin ---
[WARNING] Using platform encoding (UTF-8 actually) to read mojo metadata, i.e. build is platform dependent!
[INFO] Applying mojo extractor for language: java-annotations
[INFO] Mojo extractor for language: java-annotations found 0 mojo descriptors.
[INFO] Applying mojo extractor for language: java
[INFO] Mojo extractor for language: java found 1 mojo descriptors.
[INFO] Applying mojo extractor for language: bsh
[INFO] Mojo extractor for language: bsh found 0 mojo descriptors. 
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

Please refer to this guide for more info http://maven.apache.org/plugin-tools/maven-plugin-plugin/examples/using-annotations.html

2
  • 3
    Adding the descriptor should occur automatically when you build your plugin. Also, you don't need to declare the maven-plugin-plugin dependency as this is also automatically found when building a project with packaging maven-plugin declared. However you might not get the latest version - with mvn 3.3.9 I was getting maven-plugin-plugin 3.2, so I had to declare the dependency to specify v3.5
    – Adam
    Nov 2, 2017 at 9:51
  • ++ This is the only answer that worked for me. It looks like that the plugin runs at a different phase by default which causes it to not find any mojo entries.
    – Gray
    Jan 27, 2021 at 1:05
5

Great answers above -- I'd like to augment them by adding a resource to find the latest version: https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-plugin-plugin

April 2, 2019 -- I encountered the same error above and resolved it by using 3.6.0

1
  • It worked with target is 11
    – duyetpt
    Nov 4, 2021 at 10:40
1

Initially I thought Gyro's answer fixed the error. But later when executing the goal it failed.

mvn sample.plugin:hello-maven-plugin:1.0-SNAPSHOT:sayhi

produced

[ERROR] Could not find goal 'sayhi' in plugin sample.plugin:hello-maven-plugin:1.0-SNAPSHOT among available goals -> [Help 1]

Turns out that

skipErrorNoDescriptorsFound

only suppressed the error. i.e. It did not resolve the underlying problem. I removed this fix.

After that the solution was simple (and the cause purely my fault). When I created GreetingMojo.java I placed it in the following directory

.../Development/my-maven-plugin/src/sample/plugin/GreetingMojo.java

It needed to be under

.../Development/my-maven-plugin/src/main/Java/sample/plugin/GreetingMojo.java

1
  • Thanks, that led me to my mistake. Adding <sourceDirectory>src</sourceDirectory> in the build section would include this source folders.
    – Jan Uhlig
    May 14, 2020 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.