The main maven plugin project does not work, Mojo plugin descriptors do not generate

I am following a tutorial to create a maven plugin and cannot run mvn install without errors. The information complains that I do not have the required mojo descriptors when annotations should generate them for me. I run maven 3.0.5 and use 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 add an annotation dependency separately, since the main api plugin did not contain these classes. when I run mvn install in 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 
+59
java maven maven-plugin
Sep 25 '13 at 8:01
source share
6 answers

After reading the Jira Issue that Gyro posted , I added the following lines to my pom and everything was well compiled.

 <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> 
+34
Sep 25 '13 at 8:34
source share

Perhaps this is due to an unresolved issue in Maven: https://issues.apache.org/jira/browse/MNG-5346

For my plugin projects, I could work around by adding an explicit maven-plugin-plugin implementation:

 <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 look at the comments in the JIRA question for more complex solutions!

+49
Sep 25 '13 at 8:15
source share

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

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

This 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> 
+23
Jun 25 '15 at 6:39
source share

Just upgrade your maven plugin version to 3.3 or 3.4

  <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>3.3</version> </plugin> </plugins> </build> 

will not fix any problem (as some claim).

You must add a minimum of default-descriptor execution with the correct phase. Thus, the minimum configuration of assembly 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> 

regardless of maven-plugin-plugin version. (this can be 3.1, 3.2, 3.3 3.4 (do not check the rest)).

will give:

 ... [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ example-maven-plugin --- [WARNING] Using platform encoding (UTF-8 actually) to read mojo metadata, ie 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] ------------------------------------------------------------------------ 

Alternatively, if you do not want your pump to have built-in tags, you can use javadocs on your Mojo. For example:

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

will give:

 ... [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ example-maven-plugin --- [WARNING] Using platform encoding (UTF-8 actually) to read mojo metadata, ie 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 information http://maven.apache.org/plugin-tools/maven-plugin-plugin/examples/using-annotations.html

+11
Mar 20 '16 at 0:21
source share

The good answers are above - I would like to supplement 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 described above and solved it with 3.6.0.

0
Apr 02 '19 at 19:52
source share

Initially, I thought the gyro answer fixed the error. But later, in fulfilling the goal, he failed.

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

is produced

[ERROR] Could not find target "sayhi" in sample.plugin plugin: hello-maven-plugin: 1.0-SNAPSHOT among available targets → [Help 1]

It turns out that

skipErrorNoDescriptorsFound

only suppresses the error. those. he did not solve the main problem. I uninstalled this patch.

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

... / Development / my-Maven-plugin / SRC / sample / plugin / GreetingMojo.java

It must be under

... / Development / my-Maven-plugin / SRC / main / Java / sample / plugin / GreetingMojo.java

-one
Jul 10 '17 at 13:01 on
source share



All Articles