简体   繁体   中英

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/

Basically, mvn compile fails the first time and then succeeds when I do a second 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. Then it starts the build. Maven cannot perform this, if the generator plugin is part of the project.

Stephen Connolly wrote about this in a blog post: Maven and the "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:

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

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

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? Have you tried removing your whole repository? (maybe you've got a messed up version of generator installed there)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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