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
The Maven Plugin Plugin is used to create a Maven plugin descriptor for any Mojo's found in the source tree, to include in the JAR. It is also used to generate report files for the Mojos as well as the artifact metadata and generating a generic help goal.
Maven plugins can be written in Java or any of a number of scripting languages.
What is a Mojo? A mojo is a Maven plain Old Java Object. Each mojo is an executable goal in Maven, and a plugin is a distribution of one or more related mojos. Introduction to Plugin Development - Introduction to concepts.
Introduction. In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With