maven之为什么当我“mvn软件包”时某些目标运行两次

不点 阅读:24 2025-06-02 22:19:02 评论:0

完整的pom.xml文件可以通过here查看。正如主题所说,我不了解一件事:当我运行mvn package时,某些阶段会运行两次,如命令的输出所示:

[INFO] Scanning for projects... 
[INFO]                                                                          
[INFO] ------------------------------------------------------------------------ 
[INFO] Building uri-template 0.5-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO]  
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ uri-template --- 
[INFO]  
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ uri-template --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 2 resources 
[INFO]  
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ uri-template --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 31 source files to /home/fge/src/perso/uri-template/target/classes 
[INFO]  
[INFO] --- serviceloader-maven-plugin:1.0.2:generate (default) @ uri-template --- 
[INFO] Scanning generated classes for implementations... 
[INFO] Generating service file /home/fge/src/perso/uri-template/target/classes/META-INF/services/com.github.fge.msgsimple.serviceloader.MessageBundleProvider 
[INFO]   + com.github.fge.uritemplate.URITemplateMessageBundle 
[INFO]  
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ uri-template --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 9 resources 
[INFO]  
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ uri-template --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 20 source files to /home/fge/src/perso/uri-template/target/test-classes 
[INFO]  
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ uri-template --- 
[INFO] Surefire report directory: /home/fge/src/perso/uri-template/target/surefire-reports 
 
------------------------------------------------------- 
 T E S T S 
------------------------------------------------------- 
Running TestSuite 
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@31c480e8 
Tests run: 513, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.384 sec 
 
Results : 
 
Tests run: 513, Failures: 0, Errors: 0, Skipped: 0 
 
[INFO]  
[INFO] --- maven-bundle-plugin:2.3.7:bundle (default-bundle) @ uri-template --- 
[INFO]  
[INFO] --- maven-javadoc-plugin:2.9:jar (default) @ uri-template --- 
[INFO]  
[snip] 
[INFO] Building jar: /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT-javadoc.jar 
[INFO]  
[INFO] >>> maven-source-plugin:2.2.1:jar (default) @ uri-template >>> 
[INFO]  
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ uri-template --- 
[INFO]  
[INFO] <<< maven-source-plugin:2.2.1:jar (default) @ uri-template <<< 
[INFO]  
[INFO] --- maven-source-plugin:2.2.1:jar (default) @ uri-template --- 
[INFO] Building jar: /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT-sources.jar 
[INFO]  
[INFO] --- maven-antrun-plugin:1.7:run (default) @ uri-template --- 
[INFO] Executing tasks 
 
main: 
     [echo] /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT.jar 
     [echo] /home/fge/src/perso/uri-template/target/classes/META-INF/services/com.github.fge.msgsimple.serviceloader.MessageBundleProvider 
      [jar] Updating jar: /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT.jar 
[INFO] Executed tasks 
[INFO]  
[INFO] >>> maven-repository-plugin:2.3.1:bundle-create (default) @ uri-template >>> 
[INFO]  
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ uri-template --- 
[INFO]  
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ uri-template --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 2 resources 
[INFO]  
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ uri-template --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 31 source files to /home/fge/src/perso/uri-template/target/classes 
[INFO]  
[INFO] --- serviceloader-maven-plugin:1.0.2:generate (default) @ uri-template --- 
[INFO] Scanning generated classes for implementations... 
[INFO] Generating service file /home/fge/src/perso/uri-template/target/classes/META-INF/services/com.github.fge.msgsimple.serviceloader.MessageBundleProvider 
[INFO]   + com.github.fge.uritemplate.URITemplateMessageBundle 
[INFO]  
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ uri-template --- 
[INFO] Using 'UTF-8' encoding to copy filtered resources. 
[INFO] Copying 9 resources 
[INFO]  
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ uri-template --- 
[INFO] Changes detected - recompiling the module! 
[INFO] Compiling 20 source files to /home/fge/src/perso/uri-template/target/test-classes 
[INFO]  
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ uri-template --- 
[INFO] Skipping execution of surefire because it has already been run for this configuration 
[INFO]  
[INFO] --- maven-bundle-plugin:2.3.7:bundle (default-bundle) @ uri-template --- 
[INFO]  
[INFO] --- maven-javadoc-plugin:2.9:jar (default) @ uri-template --- 
[INFO]  
[snip] 
[INFO] Building jar: /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT-javadoc.jar 
[WARNING] Artifact com.github.fge:uri-template:javadoc:javadoc:0.5-SNAPSHOT already attached to project, ignoring duplicate 
[INFO]  
[INFO] >>> maven-source-plugin:2.2.1:jar (default) @ uri-template >>> 
[INFO]  
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ uri-template --- 
[INFO]  
[INFO] <<< maven-source-plugin:2.2.1:jar (default) @ uri-template <<< 
[INFO]  
[INFO] --- maven-source-plugin:2.2.1:jar (default) @ uri-template --- 
[WARNING] Artifact com.github.fge:uri-template:java-source:sources:0.5-SNAPSHOT already attached to project, ignoring duplicate 
[INFO]  
[INFO] --- maven-antrun-plugin:1.7:run (default) @ uri-template --- 
[INFO] Executing tasks 
 
main: 
     [echo] /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT.jar 
     [echo] /home/fge/src/perso/uri-template/target/classes/META-INF/services/com.github.fge.msgsimple.serviceloader.MessageBundleProvider 
      [jar] Updating jar: /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT.jar 
[INFO] Executed tasks 
[INFO]  
[INFO] <<< maven-repository-plugin:2.3.1:bundle-create (default) @ uri-template <<< 
[INFO]  
[INFO] --- maven-repository-plugin:2.3.1:bundle-create (default) @ uri-template --- 
[INFO] The following files are marked for inclusion in the repository bundle: 
 
0.) Done 
1.) uri-template-0.5-SNAPSHOT.jar 
2.) uri-template-0.5-SNAPSHOT-javadoc.jar 
3.) uri-template-0.5-SNAPSHOT-sources.jar 
 
Please select the number(s) for any files you wish to exclude, or '0' when you're done. 
Separate the numbers for multiple files with a comma (','). 
 
Selection:  
[INFO] Building jar: /home/fge/src/perso/uri-template/target/uri-template-0.5-SNAPSHOT-bundle.jar 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESS 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 18.700s 
[INFO] Finished at: Tue Jun 11 11:54:38 CEST 2013 
[INFO] Final Memory: 31M/338M 
[INFO] ------------------------------------------------------------------------ 

为什么会这样?如何避免这种情况?

附带问题:如何防止存储库插件交互?

请您参考如下方法:

您首先应该像下面这样更改maven-source-plugin的配置:

        <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-source-plugin</artifactId> 
            <version>2.2.1</version> 
            <executions> 
                <execution> 
                    <phase>package</phase> 
                    <goals> 
                        <goal>jar-no-fork</goal> 
                    </goals> 
                </execution> 
            </executions> 
        </plugin> 

第二,您应该注释掉maven-repository-plugin的执行,导致该插件产生生命周期:
        <plugin> 
            <groupId>org.apache.maven.plugins</groupId> 
            <artifactId>maven-repository-plugin</artifactId> 
            <version>2.3.1</version> 
            <executions> 
                <execution> 
                    <phase>package</phase> 
                    <goals> 
                        <goal>bundle-create</goal> 
                    </goals> 
                </execution> 
            </executions> 
        </plugin> 

更改上述两件事后,您将不会重复执行默认编译等。


标签:Maven
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

关注我们

一个IT知识分享的公众号