Basic maven plugin project not working, Mojo plugin descriptors not generating

浪子不回头ぞ 提交于 2019-11-29 23:27:45
Gyro Gearless

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!

coderatchet

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>
Jmini

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 how 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>

Simply incrementing 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>

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!