简体   繁体   English

Maven插件作为多模块项目中的依赖项

[英]Maven plugin as dependency in multi-module project

I'm having a problem with a multi-module project where one of the modules is an annotation-based maven-plugin: https://github.com/fommil/netlib-java/ 我遇到了一个多模块项目的问题,其中一个模块是基于注释的maven-plugin: https//github.com/fommil/netlib-java/

Basically, mvn compile fails the first time and then succeeds when I do a second mvn compile . 基本上, mvn compile第一次失败,然后在我做第二次mvn compile时成功。

It also works OK from clean if I do 如果我这样做,它也可以正常工作

mvn -pl generator compile
mvn compile

I'd like the build to succeed in one go so that I can do a build and release of all modules. 我希望构建能够一次成功,这样我就可以构建和发布所有模块。

I had a quick look at your project and found, that the "generator" plugin is part of the multimodule project and it is used (with the same version) within this project. 我在你的项目有一个快速浏览一下,结果发现,该“发电机”插件是多模块项目的一部分它被使用(使用相同版本的)这个项目中。 This is not a legal use! 这不是合法用途! You have to provide all required plugins from outside the reactor! 您必须从反应堆外部提供所有必需的插件!

The reason for this is, that maven tries to fill the reactor and determine all required plugins beforehand. 原因是,maven试图填充反应堆并事先确定所有必需的插件。 Then it starts the build. 然后它开始构建。 Maven cannot perform this, if the generator plugin is part of the project. 如果生成器插件是项目的一部分,Maven无法执行此操作。

Stephen Connolly wrote about this in a blog post: Maven and the "Install" Hack . Stephen Connolly在博客文章中写到了这一点: Maven和“Install”Hack

hth, 心连心,
- martin - 马丁

(I'm placing this as an answer because it won't fit on the comments area) (我将此作为答案,因为它不适合评论区域)

Well I downloaded the 11fe0f5 revision from Github and tried mvn clean install on the parent/root folder to see what would happen and I got this error: 好吧,我从Github下载了11fe0f5版本,并在父/根文件夹上尝试了mvn clean install,看看会发生什么,我收到了这个错误:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.444s
[INFO] Finished at: Mon Jun 24 20:00:30 BRT 2013
[INFO] Final Memory: 20M/350M
[INFO] ------------------------------------------------------------------------
[ERROR] Could not find goal 'interface' in plugin org.netlib:generator:1.0-SNAPSHOT among available goals -> [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/MojoNotFoundException

Which led me to question if the interface goal really existed in the generator plugin and if it's goal descriptor was being generated.. So looking at the generator module pom.xml I couldn't find any maven-plugin configuration in order to generate a plugin module, so I changed your maven-plugin-plugin configurations to: 这让我质疑接口目标是否真的存在于生成器插件中,以及是否正在生成目标描述符。所以看一下生成器模块pom.xml我找不到任何maven-plugin配置来生成插件模块,所以我将你的maven-plugin-plugin配置更改为:

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

and that added the interface goal to the generator plugin and I'm now able to install from the root folder just fine. 并且它将接口目标添加到生成器插件中,我现在能够从根文件夹安装就好了。

mvn clean install partial output: mvn clean install部分输出:

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ netlib ---
[INFO] Building jar: C:\ebook\netlib-java-11fe0f502496276be5536003eaacbde363317c
b1\netlib\target\netlib-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install (default-install) @ netlib ---
[INFO] Installing C:\ebook\netlib-java-11fe0f502496276be5536003eaacbde363317cb1\
netlib\target\netlib-1.0-SNAPSHOT.jar to C:\Users\oltra01\.m2\repository\org\net
lib\netlib\1.0-SNAPSHOT\netlib-1.0-SNAPSHOT.jar
[INFO] Installing C:\ebook\netlib-java-11fe0f502496276be5536003eaacbde363317cb1\
netlib\pom.xml to C:\Users\oltra01\.m2\repository\org\netlib\netlib\1.0-SNAPSHOT
\netlib-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent ............................................ SUCCESS [0.478s]
[INFO] generator ......................................... SUCCESS [6.172s]
[INFO] netlib ............................................ SUCCESS [1:05.310s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:12.105s
[INFO] Finished at: Mon Jun 24 19:55:08 BRT 2013
[INFO] Final Memory: 27M/491M
[INFO] ------------------------------------------------------------------------

What maven commands/goals are you using to get the error in your question? 您使用什么maven命令/目标来解决问题中的错误? Have you tried removing your whole repository? 您是否尝试删除整个存储库? (maybe you've got a messed up version of generator installed there) (也许你已经安装了一个混乱的发电机版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM