Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 基本maven插件项目不工作,Mojo插件描述符不生成_Java_Maven_Maven Plugin - Fatal编程技术网

Java 基本maven插件项目不工作,Mojo插件描述符不生成

Java 基本maven插件项目不工作,Mojo插件描述符不生成,java,maven,maven-plugin,Java,Maven,Maven Plugin,我遵循创建maven插件的步骤,无法运行mvn安装而不出错。信息抱怨说,当注释应该为我生成它们时,我没有所需的mojo描述符。我正在运行maven 3.0.5,并使用intellij作为我的ide。这是我的主要课程: @Mojo(name = "modify-connector") public class ComplianceMojo extends AbstractMojo { @Parameter private String artifactId; @Para

我遵循创建maven插件的步骤,无法运行mvn安装而不出错。信息抱怨说,当注释应该为我生成它们时,我没有所需的mojo描述符。我正在运行maven 3.0.5,并使用intellij作为我的ide。这是我的主要课程:

@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());
        }
    }
}
这是我的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>

这可能与Maven中未解决的问题有关:

对于我的插件项目,我可以通过添加maven插件的显式执行来解决问题:

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

org.apache.maven.plugins
maven插件
3.2
真的
魔咒描述符
描述符
但更多详细的解决方案请参见JIRA问题中的评论

阅读之后,我在pom中添加了以下几行,所有内容都编译得很好

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

org.apache.maven.plugins
maven插件
3.2
mysql jdbc遵从性
默认描述符
描述符
进程类
帮助描述符
帮助魔咒
进程类
如中所述,这是一个bug,现已修复

您只需要告诉maven它应该使用更新版本的
maven插件

以下是我的pom文件的外观:

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

org.apache.maven.plugins
maven插件
3.3

简单地将maven插件版本增加到3.3或3.4不会解决任何问题(正如一些人所说)

您必须在正确的阶段添加最少的
默认描述符
执行。 因此,构建信息的最小配置如下所示:

[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
<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>
另一个选择是,如果您不想在pom中有构建标记,可以在Mojo上使用javadocs。例如:

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

...
[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] ------------------------------------------------------------------------
...
[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] ------------------------------------------------------------------------
有关更多信息,请参阅本指南

起初,我认为陀螺仪的答案修复了错误。但后来在执行目标时失败了

插件:hello maven插件:1.0-SNAPSHOT:sayhi

产生

[错误]在插件示例中找不到目标“sayhi”。插件:hello maven插件:1.0-可用目标中的快照->[帮助1]

原来

已找到SkipPerorNodeScript脚本

只是抑制了错误。i、 e.它没有解决根本问题。我删除了这个补丁

在那之后,解决办法很简单(原因完全是我的错)。当我创建GreetingMojo.java时,我将它放在以下目录中

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

它需要被控制

…/Development/my maven plugin/src/main/Java/sample/plugin/GreetingMojo.Java

上面的答案很好--我想通过添加一个资源来查找最新版本来补充这些答案:


2019年4月2日——我遇到了上述相同的错误,并通过使用3.6.0解决了它。我已经阅读了您发布的问题,并在网站上实施了相应的解决方案,效果良好!谢谢你向我指出:)这个问题已经在3.2.2中解决了:谢谢,这解决了我在运行Maven 3.0.5的机器上的构建问题,五年后,当Maven插件在Maven 3.6.3上崩溃时,这个解决方案仍然有效。谢谢,我仍然可以在3.5+中重现这个问题,但幸运的是,同样的解决方案仍然可以解决它!谢谢如果您使用maven原型生成项目,此条目实际上会自动添加到插件的
pom.xml
:使用mvn 3.3.9生成-DgroupId=com.example-DartifactId=my awesome maven plugin-DarchetypeGroupId=org.apache.maven.archetypes-DarchetypeArtifactId=maven原型插件,我只需要mvn 3.3.9groupId、artifactId和v3.5-所有配置都是默认配置。在构建插件时,应该自动添加描述符。此外,您不需要声明maven插件依赖项,因为在构建一个已声明打包
maven插件的项目时,也会自动发现这一依赖项。但是,您可能无法获得最新版本-使用MVN3.3.9,我获得了maven插件3.2,因此我必须声明依赖项以指定v3.5++这是唯一对我有效的答案。默认情况下,插件运行在不同的阶段,这导致插件找不到任何mojo条目。2019-06版本为3.6.1-10@jordiburgos为2019-07-16(于2018-10-29更新)的最新版本指定了3.6.0。谢谢,这导致了我的错误。在build部分中添加src将包括此源文件夹。