Artifact has not been packaged yet. When used on reactor art
最初在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:WorkSpace3parentProj mvn clean install
输出如下:
Microsoft Windows [版本 6.1.7601] ②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包不存在只能说是插件有点小瑕疵。不用管他了。
process-test-classes 阶段都行。
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ===========================***================================== 下面是mod2中将插件绑定到 process-test-classes 阶段的构建结果,效果是一样的: ===========================***================================== D:WorkSpace3parentProj>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:WorkSpace3parentProjpom.xml to E:repocomlxparentProj .0.1-SNAPSHOTparentProj-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:WorkSpace3parentProjmod2target [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:WorkSpace3parentProjmod2targetclasses [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:WorkSpace3parentProjmod2targettest-classes [INFO] [INFO] --- maven-jar-plugin:2.4:test-jar (pack-test-jar) @ mod2 --- [INFO] Building jar: D:WorkSpace3parentProjmod2targetmod2-0.0.1-SNAPSHOT-tests.jar [INFO] [INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod2 --- [INFO] Surefire report directory: D:WorkSpace3parentProjmod2targetsurefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running mod2.Mod2Test mod2 测试............ Tests run: 1,Time elapsed: 0.065 sec - in mod2.Mod2Test Results : Tests run: 1,Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod2 --- [INFO] Building jar: D:WorkSpace3parentProjmod2targetmod2-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ mod2 --- [INFO] Installing D:WorkSpace3parentProjmod2targetmod2-0.0.1-SNAPSHOT.jar to E:repocomlxmod2 .0.1-SNAPSHOTmod2-0.0.1-SNAPSHOT.jar [INFO] Installing D:WorkSpace3parentProjmod2pom.xml to E:repocomlxmod2 .0.1-SNAPSHOTmod2-0.0.1-SNAPSHOT.pom [INFO] Installing D:WorkSpace3parentProjmod2targetmod2-0.0.1-SNAPSHOT-tests.jar to E:repocomlxmod2 .0.1-SNAPSHOTmod2-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:WorkSpace3parentProjmod1target [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:WorkSpace3parentProjmod1targetclasses [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:WorkSpace3parentProjmod1targetmod1-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ mod1 --- [INFO] Installing D:WorkSpace3parentProjmod1targetmod1-0.0.1-SNAPSHOT.jar to E:repocomlxmod1 .0.1-SNAPSHOTmod1-0.0.1-SNAPSHOT.jar [INFO] Installing D:WorkSpace3parentProjmod1pom.xml to E:repocomlxmod1 .0.1-SNAPSHOTmod1-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:WorkSpace3parentProjmod-testtarget [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:WorkSpace3parentProjmod-testtargetclasses [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:WorkSpace3parentProjmod-testtargetmod-test-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-test --- [INFO] Installing D:WorkSpace3parentProjmod-testtargetmod-test-0.0.1-SNAPSHOT.jar to E:repocomlxmod-test .0.1-SNAPSHOTmod-test-0.0.1-SNAPSHOT.jar [INFO] Installing D:WorkSpace3parentProjmod-testpom.xml to E:repocomlxmod-test .0.1-SNAPSHOTmod-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:WorkSpace3parentProjmod-alltarget [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:WorkSpace3parentProjmod-allsrcmainresources [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:WorkSpace3parentProjmod-allsrctestresources [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:WorkSpace3parentProjmod-alltargetmod-all-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ mod-all --- [INFO] Installing D:WorkSpace3parentProjmod-alltargetmod-all-0.0.1-SNAPSHOT.jar to E:repocomlxmod-all .0.1-SNAPSHOTmod-all-0.0.1-SNAPSHOT.jar [INFO] Installing D:WorkSpace3parentProjmod-allpom.xml to E:repocomlxmod-all .0.1-SNAPSHOTmod-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:WorkSpace3parentProjmod-parentpom.xml to E:repocomlxmod-parent .0.1-SNAPSHOTmod-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:WorkSpace3parentProjmod-parentmod3target [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:WorkSpace3parentProjmod-parentmod3srcmainresources [INFO] [INFO] --- maven-compiler-plugin:3.0:compile (default-compile) @ mod3 --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to D:WorkSpace3parentProjmod-parentmod3targetclasses [INFO] [INFO] --- maven-dependency-plugin:2.8:build-classpath (generate-cached-classpath) @ mod3 --- [INFO] Wrote classpath file 'D:WorkSpace3parentProjmod-parentmod3targetcached_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:WorkSpace3parentProjmod-parentmod3srctestresources [INFO] [INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) @ mod3 --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to D:WorkSpace3parentProjmod-parentmod3targettest-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:WorkSpace3parentProjmod2targetmod2-0.0.1-SNAPSHOT-tests.jar to D:WorkSpace3parentProjmod-parentmod3targettest-classes with includes "" and excludes "" [INFO] [INFO] --- maven-surefire-plugin:2.15:test (default-test) @ mod3 --- [INFO] Surefire report directory: D:WorkSpace3parentProjmod-parentmod3targetsurefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- Running mod2.Mod2Test mod2 测试............ Tests run: 1,Time elapsed: 0.074 sec - in mod2.Mod2Test Running org.mod3.Mod3Test mod3 测试.................. Tests run: 1,Time elapsed: 0.004 sec - in org.mod3.Mod3Test Results : Tests run: 2,Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mod3 --- [INFO] Building jar: D:WorkSpace3parentProjmod-parentmod3targetmod3-0.0.1-SNAPSHOT.jar [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ mod3 --- [INFO] Installing D:WorkSpace3parentProjmod-parentmod3targetmod3-0.0.1-SNAPSHOT.jar to E:repocomlxmod3 .0.1-SNAPSHOTmod3-0.0.1-SNAPSHOT.jar [INFO] Installing D:WorkSpace3parentProjmod-parentmod3pom.xml to E:repocomlxmod3 .0.1-SNAPSHOTmod3-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] ------------------------------------------------------------------------ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |