Maven 打包問題

1、問題描述

今天給聚合工程統一打包時出現這樣一個異常packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109。完整異常如下:

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project cn.edu.njust:mango_pom:1.0-SNAPSHOT (D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_pom\pom.xml) has 1 error
[ERROR]     'packaging' with value 'jar' is invalid. Aggregator projects require 'pom' as packaging. @ line 4, column 109
[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/ProjectBuildingException

Process finished with exit code 1

2、問題分析

出錯的pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cn.edu.njust</groupId>
    <artifactId>mango_pom</artifactId>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>../mango_common</module>
        <module>../mango_core</module>
        <module>../mango</module>
    </modules>

</project>

  這是由於統一打包的工程不生成jar包文件,所以需要使用pom格式打包,即<packaging>pom</packaging>。完整正確pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>

    <groupId>cn.edu.njust</groupId>
    <artifactId>mango_pom</artifactId>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>../mango_common</module>
        <module>../mango_core</module>
        <module>../mango</module>
    </modules>

</project>

3、問題解決

運行程序,結果輸出如下:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] mango-common                                                       [jar]
[INFO] mango_core                                                         [jar]
[INFO] mango                                                              [jar]
[INFO] mango_pom                                                          [pom]
[INFO] 
[INFO] ---------------------< cn.edu.njust:mango-common >----------------------
[INFO] Building mango-common 1.0-SNAPSHOT                                 [1/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mango-common ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mango-common ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mango-common ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_common\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mango-common ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mango-common ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mango-common ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mango-common ---
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_common\target\mango-common-1.0-SNAPSHOT.jar to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango-common\1.0-SNAPSHOT\mango-common-1.0-SNAPSHOT.jar
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_common\pom.xml to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango-common\1.0-SNAPSHOT\mango-common-1.0-SNAPSHOT.pom
[INFO] 
[INFO] ----------------------< cn.edu.njust:mango_core >-----------------------
[INFO] Building mango_core 1.0-SNAPSHOT                                   [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mango_core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mango_core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mango_core ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_core\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mango_core ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mango_core ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mango_core ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mango_core ---
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_core\target\mango_core-1.0-SNAPSHOT.jar to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango_core\1.0-SNAPSHOT\mango_core-1.0-SNAPSHOT.jar
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_core\pom.xml to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango_core\1.0-SNAPSHOT\mango_core-1.0-SNAPSHOT.pom
[INFO] 
[INFO] -------------------------< cn.edu.njust:mango >-------------------------
[INFO] Building mango 0.0.1-SNAPSHOT                                      [3/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ mango ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 12 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ mango ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ mango ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ mango ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ mango ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ mango ---
[INFO] Building jar: D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango\target\mango-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.2.6.RELEASE:repackage (repackage) @ mango ---
[INFO] Replacing main artifact with repackaged archive
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ mango ---
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango\target\mango-0.0.1-SNAPSHOT.jar to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango\0.0.1-SNAPSHOT\mango-0.0.1-SNAPSHOT.jar
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango\pom.xml to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango\0.0.1-SNAPSHOT\mango-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] -----------------------< cn.edu.njust:mango_pom >-----------------------
[INFO] Building mango_pom 1.0-SNAPSHOT                                    [4/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mango_pom ---
[INFO] Installing D:\nanligong\mianshi\project\20200505\fuxi\springcloudproject\mongo_back02\mango_pom\pom.xml to D:\nanligong\program\java\maven\repos\cn\edu\njust\mango_pom\1.0-SNAPSHOT\mango_pom-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] mango-common ....................................... SUCCESS [  1.477 s]
[INFO] mango_core ......................................... SUCCESS [  0.045 s]
[INFO] mango 0.0.1-SNAPSHOT ............................... SUCCESS [  3.562 s]
[INFO] mango_pom 1.0-SNAPSHOT ............................. SUCCESS [  0.009 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.091 s
[INFO] Finished at: 2020-05-06T13:06:40+08:00
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "nexus" could not be activated because it does not exist.

Process finished with exit code 0

打包成功!

4、總結

  書上的代碼直接運行絕大部分是對的,但是總有一些軟件的更新使得作者無能爲力。之前的API是對的,但是之後就廢棄了或修改了是常有的事。所以我們需要跟蹤源代碼。這只是一個小小的問題,如果沒有前輩的無私奉獻,很難想象我們自己一天能學到多少內容。感謝各位前輩的辛勤付出,讓我們少走了很多的彎路!

點個贊再走唄!歡迎留言哦!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章