Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can Maven not find my custom Mojo?

Tags:

I have an own Mojo class.

 @Mojo(name="mojo", threadSafe=true)  public class MyMojo extends AbstractMojo  {      @Component      private MavenProject project;       public void execute() throws MojoExecutionException, MojoFailureException      {         getLog().info("Execute");      }   } 

After that I install it in local repository.

 [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 0 mojo descriptors.  [INFO] Applying mojo extractor for language: bsh  [INFO] Mojo extractor for language: bsh found 0 mojo descriptors.  ....  [INFO] BUILD SUCCESS 

But when try to call 'mojo' goal I got en error

   [ERROR] Could not find goal 'mojo' in plugin my.plugins:my-plugin:1.0-SNAPSHOT among available goals -> [Help 1]  what is the problem? 

Here is maven-plugin-plugin configuration.

<plugin>     <groupId>org.apache.maven.plugins</groupId>     <artifactId>maven-plugin-plugin</artifactId>     <version>3.2</version>     <configuration>                                                          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>      </configuration>  </plugin> 

Old mechanism with javadoc annotations works well, but i want to use java annotation.

<dependency>     <groupId>org.apache.maven.plugin-tools</groupId>     <artifactId>maven-plugin-annotations</artifactId>     <version>3.2</version> </dependency>    [INFO] --- maven-plugin-plugin:3.2:descriptor (default-descriptor) @ bla-mvn-plugin  

Why default-descriptor is enabled instead of mojo-descriptor?

like image 273
yu.pitomets Avatar asked Jan 18 '13 16:01

yu.pitomets


People also ask

Does Maven allow third party plugins?

plugins for prefix-to-artifactId mappings for the plugins it needs to perform a given build. However, as previously mentioned, the user may have a need for third-party plugins.

What is Mojo in Maven terms?

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.

What is the default language for a Maven mojo?

Maven plugins can be written in Java or any of a number of scripting languages.

What plugins does Maven use?

Plugin Configuration Maven has two types of plugins: Build – executed during the build process. Examples include Clean, Install, and Surefire plugins. These should be configured in the build section of the POM.


1 Answers

Add this section to your plugin's POM:

<build>     <pluginManagement>         <plugins>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-plugin-plugin</artifactId>                 <version>3.2</version>                 <configuration>                     <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>                 </configuration>                 <executions>                     <execution>                         <id>mojo-descriptor</id>                         <phase>process-classes</phase>                         <goals>                             <goal>descriptor</goal>                         </goals>                     </execution>                 </executions>             </plugin>         </plugins>     </pluginManagement> </build> 

PS. See maven-compiler-plugin:3.0 sources for full working example of building MOJOs with annotations

like image 51
ZhekaKozlov Avatar answered Sep 27 '22 22:09

ZhekaKozlov