Artifact has not been packaged yet. When used on reactor artifact, unpack should be executed after p

本文通过实例展示了Maven在构建多模块项目时如何智能决定构建顺序,并解释了一个常见的m2eclipse插件误报错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最初在titan的源码里看到这个错误的。搜了一下这个错是eclipse的插件m2e的问题。不是真正的错误。

这是验证代码。这个验证代码可以让你更加了解多模块工程时maven会智能的决定最先构建哪个模块。每个模块都有自己的构建周期,xml没有写错。

可以用一个<pluginManagement>把插件包住,这样eclipse里就不报错了。但是<pluginManagement>的使用场景是父项目里定义,然后子项目里继承使用。 这里加一个<pluginManagement>只是为了看不到这个错误感觉有点名不正言不顺。 最好的办法就是忽略,不去管他。我试过了,jdk1.7+eclipse mars版本,或者 jdk1.8+eclipse neon.1版本都是会报这个错的。maven的版本都是3.3.9。


下面验证一下这个错误不影响使用。

1.新建一个maven项目叫parentProj. 

2.建子模块mod-all,mod-parent,mod-test。其中mod-all包含子模块 mod1,mod2。 mod-parent包含子模块mod-3。(titan的源码里就是个样子的)

3.在mod-parent的pom.xml里加入

<pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>
              <id>generate-cached-classpath</id>
              <phase>generate-test-resources</phase>
              <goals>
                <goal>build-classpath</goal>
              </goals>
              <configuration>
                <outputFile>${project.basedir}/target/cached_classpath.txt</outputFile>
              </configuration>
            </execution>
            <execution>
              <id>unpack-common-test-classes</id>
              <phase>process-test-classes</phase>
              <goals>
                <goal>unpack</goal>
              </goals>
              <configuration>
                <artifactItems>
                  <artifactItem>
                    <groupId>${project.groupId}</groupId>
                    <artifactId>mod2</artifactId>
                    <version>${project.version}</version>
                    <classifier>tests</classifier>
                    <outputDirectory>${project.build.directory}/test-classes</outputDirectory>
                  </artifactItem>
                </artifactItems>
              </configuration>
            </execution>
          </executions>
        </plugin>

        <!--This plugin's configuration is used to store Eclipse m2e settings 
          only. It has no influence on the Maven build itself. -->
        <plugin>
          <groupId>org.eclipse.m2e</groupId>
          <artifactId>lifecycle-mapping</artifactId>
          <version>1.0.0</version>
          <configuration>
            <lifecycleMappingMetadata>
              <pluginExecutions>
                <pluginExecution>
                  <pluginExecutionFilter>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <versionRange>[2.2.1,)</versionRange>
                    <goals>
                      <goal>build-classpath</goal>
                      <goal>unpack</goal>
                    </goals>
                  </pluginExecutionFilter>
                  <action>
                    <execute />
                  </action>
                </pluginExecution>
              </pluginExecutions>
            </lifecycleMappingMetadata>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>


然后在mod3里加入


<plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>generate-cached-classpath</id>
          </execution>
          <!-- 为什么此处可以解压mod2-tests.jar? 因为maven构建一开始的时候就已经reorder了。可以看到mod2是最先执行的,构建完mod2之后才开始构建mod3的 -->
          <execution>
            <id>unpack-common-test-classes</id>
          </execution>
        </executions>
</plugin>


此时在<execution>处就会报

Artifact has not been packaged yet. When used on reactor artifact, unpack should be executed after packaging: see MDEP-98.


4.加入测试代码

mod1里有一个类叫ModA。里面有一个方法printA

mod2里有一个类叫ModB。里面有一个方法printB

printA里调用了ModB的printB方法

mod-test里有一个以Test开头的类。 类里有一个方法调用ModA的printA方法


mod-all

    |-- mod1

        |-- ModA

    |-- mod2

        |-- ModB

mod-parent

    |--mod3

mod-test

    |-- TestModA


5.测试

cd /d D:\WorkSpace3\parentProj

mvn clean install


输出如下:


Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。


C:\Users\Administrator>cd /d D:\WorkSpace3\parentProj


D:\WorkSpace3\parentProj>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parentProj
[INFO] mod2
[INFO] mod1
[INFO] mod-test
[INFO] mod-all
[INFO] mod-parent
[INFO] mod3
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parentProj 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parentProj ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ parentProj ---
[INFO] Installing D:\WorkSpace3\parentProj\pom.xml to E:\repo\com\lx\parentProj\0.0.1-SNAPSHOT\parentProj-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod2 ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod2\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod2\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod2\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod2 ---
[INFO] Surefire report directory: D:\WorkSpace3\parentProj\mod2\target\surefire-reports


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running mod2.Mod2Test
mod2 测试............
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.056 sec - in mod2.Mod2Test


Results :


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


[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod2 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-jar-plugin:2.4:test-jar (pack-test-jar) @ mod2 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT-tests.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod2 ---
[INFO] Installing D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod2\0.0.1-SNAPSHOT\mod2-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod2\pom.xml to E:\repo\com\lx\mod2\0.0.1-SNAPSHOT\mod2-0.0.1-SNAPSHOT.pom
[INFO] Installing D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT-tests.jar to E:\repo\com\lx\mod2\0.0.1-SNAPSHOT\mod2-0.0.1-SNAPSHOT-tests.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod1 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod1 ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod1\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod1\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod1 ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod1 ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod1 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod1\target\mod1-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod1 ---
[INFO] Installing D:\WorkSpace3\parentProj\mod1\target\mod1-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod1\0.0.1-SNAPSHOT\mod1-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod1\pom.xml to E:\repo\com\lx\mod1\0.0.1-SNAPSHOT\mod1-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod-test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod-test ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod-test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod-test ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod-test ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod-test ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod-test\target\mod-test-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-test ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-test\target\mod-test-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod-test\0.0.1-SNAPSHOT\mod-test-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod-test\pom.xml to E:\repo\com\lx\mod-test\0.0.1-SNAPSHOT\mod-test-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod-all 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod-all ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod-all\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod-all ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-all\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod-all ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod-all ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-all\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod-all ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod-all ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod-all ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: D:\WorkSpace3\parentProj\mod-all\target\mod-all-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-all ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-all\target\mod-all-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod-all\0.0.1-SNAPSHOT\mod-all-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod-all\pom.xml to E:\repo\com\lx\mod-all\0.0.1-SNAPSHOT\mod-all-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod-parent 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod-parent ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-parent ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-parent\pom.xml to E:\repo\com\lx\mod-parent\0.0.1-SNAPSHOT\mod-parent-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod3 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod3 ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod-parent\mod3\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod3 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-parent\mod3\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod3 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod-parent\mod3\target\classes
[INFO]
[INFO] --- maven-dependency-plugin:2.8:build-classpath (generate-cached-classpath) @ mod3 ---
[INFO] Wrote classpath file 'D:\WorkSpace3\parentProj\mod-parent\mod3\target\cached_classpath.txt'.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod3 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-parent\mod3\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod3 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod-parent\mod3\target\test-classes
[INFO]
[INFO] --- maven-dependency-plugin:2.8:unpack (unpack-common-test-classes) @ mod3 ---
[INFO] Configured Artifact: com.lx:mod2:tests:0.0.1-SNAPSHOT:jar
[INFO] Unpacking D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT-tests.jar to D:\WorkSpace3\parentProj\mod-parent\mod3\target\test-classes with includes "" and excludes ""
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod3 ---
[INFO] Surefire report directory: D:\WorkSpace3\parentProj\mod-parent\mod3\target\surefire-reports


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running mod2.Mod2Test
mod2 测试............
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.078 sec - in mod2.Mod2Test
Running org.mod3.Mod3Test
mod3 测试..................
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec - in org.mod3.Mod3Test


Results :


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


[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod3 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod-parent\mod3\target\mod3-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod3 ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-parent\mod3\target\mod3-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod3\0.0.1-SNAPSHOT\mod3-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod-parent\mod3\pom.xml to E:\repo\com\lx\mod3\0.0.1-SNAPSHOT\mod3-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parentProj ......................................... SUCCESS [  0.595 s]
[INFO] mod2 ............................................... SUCCESS [  2.787 s]
[INFO] mod1 ............................................... SUCCESS [  0.332 s]
[INFO] mod-test ........................................... SUCCESS [  0.303 s]
[INFO] mod-all ............................................ SUCCESS [  0.287 s]
[INFO] mod-parent ......................................... SUCCESS [  0.069 s]
[INFO] mod3 ............................................... SUCCESS [  1.840 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.730 s
[INFO] Finished at: 2016-10-27T14:32:15+08:00
[INFO] Final Memory: 21M/219M
[INFO] ------------------------------------------------------------------------


以上结果可以看出
①可以看到maven会先分析项目依赖,然后调整编译的顺序,因为mod-test调用了printA, 而printA调用了printB。所以最小构建的是mod2子模块,然后再是mod1子模块。再接着是mod-test...

②maven的phase会在每个子模块里先走完。比如最先构建的是mod2。先在mod2里完整的走一遍maven的几个阶段,走到test阶段的时候会先执行mod2里的测试程序。走到package阶段就会打jar包。上面忘了说了,在mod2的src/main/test里有一个测试的类。有一个方法上加了@Test。

③正因为有了②,所以在build mod2的时候就已经打包好了mod2-0.0.1-SNAPSHOT-tests.jar,所以咱们的 mod3里在构建的时候要解压mod2-0.0.1-SNAPSHOT-tests.jar这个jar包是没问题的。因为人家的确存在呀。 所以这里报jar包不存在只能说是插件有点小瑕疵。不用管他了。



maven在构建的时候有很多阶段。比如下面在mod2中将打包的插件绑定到process-test-classes 阶段也是可以的。因为mod2在mod3之前构建,所以绑定到package或绑定到

 process-test-classes 阶段都行。


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


===========================***==================================
下面是mod2中将插件绑定到 process-test-classes 阶段的构建结果,效果是一样的:
===========================***==================================
D:\WorkSpace3\parentProj>mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parentProj
[INFO] mod2
[INFO] mod1
[INFO] mod-test
[INFO] mod-all
[INFO] mod-parent
[INFO] mod3
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building parentProj 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parentProj ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ parentProj ---
[INFO] Installing D:\WorkSpace3\parentProj\pom.xml to E:\repo\com\lx\parentProj\0.0.1-SNAPSHOT\parentProj-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod2 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod2 ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod2\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod2\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod2 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod2 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod2\target\test-classes
[INFO]
[INFO] --- maven-jar-plugin:2.4:test-jar (pack-test-jar) @ mod2 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT-tests.jar
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod2 ---
[INFO] Surefire report directory: D:\WorkSpace3\parentProj\mod2\target\surefire-reports


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running mod2.Mod2Test
mod2 测试............
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.065 sec - in mod2.Mod2Test


Results :


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


[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod2 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod2 ---
[INFO] Installing D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod2\0.0.1-SNAPSHOT\mod2-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod2\pom.xml to E:\repo\com\lx\mod2\0.0.1-SNAPSHOT\mod2-0.0.1-SNAPSHOT.pom
[INFO] Installing D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT-tests.jar to E:\repo\com\lx\mod2\0.0.1-SNAPSHOT\mod2-0.0.1-SNAPSHOT-tests.jar
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod1 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod1 ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod1\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod1\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod1 ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod1 ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod1 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod1\target\mod1-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod1 ---
[INFO] Installing D:\WorkSpace3\parentProj\mod1\target\mod1-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod1\0.0.1-SNAPSHOT\mod1-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod1\pom.xml to E:\repo\com\lx\mod1\0.0.1-SNAPSHOT\mod1-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod-test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod-test ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod-test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod-test ---
[INFO] Changes detected - recompiling the module!
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod-test ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod-test ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod-test\target\mod-test-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-test ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-test\target\mod-test-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod-test\0.0.1-SNAPSHOT\mod-test-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod-test\pom.xml to E:\repo\com\lx\mod-test\0.0.1-SNAPSHOT\mod-test-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod-all 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod-all ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod-all\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod-all ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-all\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod-all ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod-all ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-all\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod-all ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod-all ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod-all ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: D:\WorkSpace3\parentProj\mod-all\target\mod-all-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-all ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-all\target\mod-all-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod-all\0.0.1-SNAPSHOT\mod-all-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod-all\pom.xml to E:\repo\com\lx\mod-all\0.0.1-SNAPSHOT\mod-all-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod-parent 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod-parent ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-parent ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-parent\pom.xml to E:\repo\com\lx\mod-parent\0.0.1-SNAPSHOT\mod-parent-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building mod3 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mod3 ---
[INFO] Deleting D:\WorkSpace3\parentProj\mod-parent\mod3\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mod3 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-parent\mod3\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod3 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod-parent\mod3\target\classes
[INFO]
[INFO] --- maven-dependency-plugin:2.8:build-classpath (generate-cached-classpath) @ mod3 ---
[INFO] Wrote classpath file 'D:\WorkSpace3\parentProj\mod-parent\mod3\target\cached_classpath.txt'.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mod3 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\WorkSpace3\parentProj\mod-parent\mod3\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod3 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\WorkSpace3\parentProj\mod-parent\mod3\target\test-classes
[INFO]
[INFO] --- maven-dependency-plugin:2.8:unpack (unpack-common-test-classes) @ mod3 ---
[INFO] Configured Artifact: com.lx:mod2:tests:0.0.1-SNAPSHOT:jar
[INFO] Unpacking D:\WorkSpace3\parentProj\mod2\target\mod2-0.0.1-SNAPSHOT-tests.jar to D:\WorkSpace3\parentProj\mod-parent\mod3\target\test-classes with includes "" and excludes ""
[INFO]
[INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod3 ---
[INFO] Surefire report directory: D:\WorkSpace3\parentProj\mod-parent\mod3\target\surefire-reports


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running mod2.Mod2Test
mod2 测试............
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.074 sec - in mod2.Mod2Test
Running org.mod3.Mod3Test
mod3 测试..................
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.004 sec - in org.mod3.Mod3Test


Results :


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


[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod3 ---
[INFO] Building jar: D:\WorkSpace3\parentProj\mod-parent\mod3\target\mod3-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mod3 ---
[INFO] Installing D:\WorkSpace3\parentProj\mod-parent\mod3\target\mod3-0.0.1-SNAPSHOT.jar to E:\repo\com\lx\mod3\0.0.1-SNAPSHOT\mod3-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\WorkSpace3\parentProj\mod-parent\mod3\pom.xml to E:\repo\com\lx\mod3\0.0.1-SNAPSHOT\mod3-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parentProj ......................................... SUCCESS [  0.444 s]
[INFO] mod2 ............................................... SUCCESS [  2.601 s]
[INFO] mod1 ............................................... SUCCESS [  0.285 s]
[INFO] mod-test ........................................... SUCCESS [  0.272 s]
[INFO] mod-all ............................................ SUCCESS [  0.204 s]
[INFO] mod-parent ......................................... SUCCESS [  0.055 s]
[INFO] mod3 ............................................... SUCCESS [  1.846 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.959 s
[INFO] Finished at: 2016-10-27T14:13:42+08:00
[INFO] Final Memory: 22M/213M
[INFO] ------------------------------------------------------------------------





<think>嗯,用户遇到了一个Maven构建错误,提示Artifact 'jp.co.kirin:dd-com:jar:0.0.1-SNAPSHOT'还没有被打包,目录还存在。错误还提到了MDEP-187,需要确保在打包之后执行复制操作。首先,我得回想一下Maven的生命周期阶段顺序。 用户可能是在多模块项目中使用maven-dependency-plugin来复制某个模块的artifact,但执行时机不对。比如,可能在父模块中过早地执行了dependency:copy,而此时子模块还没有完成打包,导致插件找不到生成的jar文件,因为目录仍然存在,但jar还没生成。 接下来,我需要检查用户插件配置中的phase和goal是否正确。通常,打包阶段是package,所以应该确保copy操作绑定在package阶段之后,比如verify阶段。另外,是否在插件配置中正确设置了依赖项目的artifactId,确保引用的模块确实会被先构建。 可能还需要确认子模块的pom.xml是否正确配置了packaging为jar,以及是否在父模块中正确声明了模块顺序。此外,Maven的反应堆构建顺序是否正确,可能通过调整模块的顺序或使用-pl和-am参数来确保依赖模块先构建。 然后,解决方案可能包括调整插件执行的阶段到verify,或者使用前置声明,比如在子模块中配置插件,确保在打包完成后执行复制。另外,检查是否有其他插件干扰了构建流程,或者是否有自定义的生命周期绑定导致的问题。 可能还需要提醒用户清理项目并重新构建,有时候旧的目录残留可能导致问题。执行mvn clean install可能会解决,因为clean会删除旧目录,install会触发完整的生命周期包括打包。 最后,需要以清晰的结构向用户解释错误原因,分步骤说明如何调整插件配置,并验证解决方案是否有效。确保用户能理解Maven的生命周期阶段和插件执行顺序的重要性,避免未来类似问题。</think>这个错误提示涉及Maven多模块项目的构建顺序和`maven-dependency-plugin`插件使用问题。以下是逐步分析及解决方案: --- ### **错误原因分析** 1. **核心问题** 在Maven多模块项目中,尝试直接复制尚未构建完成的模块产物(`jp.co.kirin:dd-com:jar:0.0.1-SNAPSHOT`)。此时目标模块仅生成目录而未生成最终的`.jar`文件。 2. **Maven生命周期阶段** Maven的构建过程遵循严格的生命周期阶段(如`compile`→`package`→`install`)。若在依赖模块未完成`package`阶段前执行`dependency:copy`,会因产物未生成而报错。 3. **MDEP-187引用** 此问题对应Maven官方编号[MDEP-187](https://issues.apache.org/jira/browse/MDEP-187),明确要求复制操作必须在目标模块完成打包后执行。 --- ### **解决方案** #### 步骤1:调整插件执行阶段 在`pom.xml`中配置`maven-dependency-plugin`,将`copy`操作绑定到**打包完成后**的阶段(如`verify`): ```xml <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>3.3.0</version> <executions> <execution> <phase>verify</phase> <!-- 改为打包后的阶段 --> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>jp.co.kirin</groupId> <artifactId>dd-com</artifactId> <version>0.0.1-SNAPSHOT</version> <type>jar</type> </artifactItem> </artifactItems> </configuration> </execution> </executions> </plugin> ``` #### 步骤2:验证模块依赖顺序 确保父模块的`<modules>`声明中,被依赖的模块(`dd-com`)**优先于**依赖它的模块: ```xml <modules> <module>dd-com</module> <!-- 被依赖的模块在前 --> <module>other-module</module> </modules> ``` #### 步骤3:强制触发完整构建 执行构建命令时,显式指定生命周期阶段以确保顺序: ```bash mvn clean package dependency:copy # 或使用默认完整构建 mvn clean install ``` --- ### **补充说明** - **目录残留问题** 若构建中断可能导致残留目录,使用`mvn clean`清理旧文件。 - **反应堆构建顺序** 使用`mvn -pl <module> -am`可指定模块构建顺序(如`mvn -pl dd-com -am package`)。 - **多模块协作验证** 单独构建目标模块以确认其能否独立生成`.jar`: ```bash cd dd-com mvn clean package ``` --- 通过调整插件执行时机和验证模块依赖顺序,可解决此问题。若仍遇到问题,建议检查子模块的`packaging`类型是否为`jar`,并确保无其他插件干扰构建流程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值