【问题标题】:Maven must compile before install (package) in mutil module maven projectmaven 必须在 mutil 模块 maven 项目中安装(包)之前编译
【发布时间】:2021-05-29 14:30:04
【问题描述】:

我有一个这样的 Spring boot maven 项目(mutil-module):

-parent
|
|-child1
| |-src
| |-pom.xml
|
|-child2
| |-src
| |-pom.xml
|
|-pom.xml

问题:

  • 我必须先运行mvn compile,然后才能运行mvn packagemvn install
  • 如果我运行 mvn clean install,那么构建将失败
  • 我猜:当install(package) 在生命周期中忽略compile 时会发生一些事情。 -- 如果package 没有compile 首先跟踪错误
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /F:/Workspace/Chinese-Chess-World/Public-Repo/Chinese-Chess-World/Chinese-Chess-World/ccw-game-service-contract/src/main/java/com/doubleat/ccw/usermanagement/CcwGameServiceContractApplication.java:[3,40] package com.doubleat
.ccw.common.constant does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ccw-platform 1.0:
[INFO]
[INFO] ccw-platform ....................................... SUCCESS [  0.479 s]
[INFO] ccw-common ......................................... SUCCESS [  2.070 s]
[INFO] ccw-config-service ................................. SUCCESS [  0.585 s]
[INFO] ccw-game-service-contract .......................... FAILURE [  0.666 s]
[INFO] ccw-game-service ................................... SKIPPED
[INFO] ccw-user-management-service-contract ............... SKIPPED
[INFO] ccw-user-management-service ........................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.110 s
[INFO] Finished at: 2021-02-27T19:21:18+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ccw-game-service-contract: Compilation failure
[ERROR] /F:/Workspace/Chinese-Chess-World/Public-Repo/Chinese-Chess-World/Chinese-Chess-World/ccw-game-service-contract/src/main/java/com/doubleat/ccw/usermanagement/CcwGameServiceContractApplication.java:[3,40] package com.doubleat
.ccw.common.constant does not exist
[ERROR]
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ccw-game-service-contract: Compilation failure
/F:/Workspace/Chinese-Chess-World/Public-Repo/Chinese-Chess-World/Chinese-Chess-World/ccw-game-service-contract/src/main/java/com/doubleat/ccw/usermanagement/CcwGameServiceContractApplication.java:[3,40] package com.doubleat.ccw.com
mon.constant does not exist

-- 完整的细节

F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World>mvn install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-common:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-common:${ccw-common.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\pom.xml, line
14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-config-service:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-config-service:${ccw-config-service.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-confi
g-service\pom.xml, line 14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-game-service-contract:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-game-service-contract:${ccw-game-service-contract.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-W
orld\ccw-game-service-contract\pom.xml, line 14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-user-management-service:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-user-management-service:${ccw-user-management-service.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Che
ss-World\ccw-user-management-service\pom.xml, line 14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-user-management-service-contract:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-user-management-service-contract:${ccw-user-management-service-contract.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess
-World\Chinese-Chess-World\ccw-user-management-service-contract\pom.xml, line 14, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ccw-platform                                                       [pom]
[INFO] ccw-common                                                         [jar]
[INFO] ccw-config-service                                                 [jar]
[INFO] ccw-game-service-contract                                          [jar]
[INFO] ccw-game-service                                                   [jar]
[INFO] ccw-user-management-service-contract                               [jar]
[INFO] ccw-user-management-service                                        [jar]
[INFO]
[INFO] -------------------< com.doubleat.ccw:ccw-platform >--------------------
[INFO] Building ccw-platform 1.0                                          [1/7]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ ccw-platform ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ ccw-platform ---
[INFO] Installing F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\pom.xml to C:\Users\Admin\.m2\repository\com\doubleat\ccw\ccw-platform\1.0\ccw-platform-1.0.pom
[INFO]
[INFO] --------------------< com.doubleat.ccw:ccw-common >---------------------
[INFO] Building ccw-common 1.0                                            [2/7]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ ccw-common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ccw-common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\target\classes
Terminate batch job (Y/N)? y

F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World>mvn -e install -Dmaven.test.skip=true
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-common:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-common:${ccw-common.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\pom.xml, line
14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-config-service:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-config-service:${ccw-config-service.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-confi
g-service\pom.xml, line 14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-game-service-contract:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-game-service-contract:${ccw-game-service-contract.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-W
orld\ccw-game-service-contract\pom.xml, line 14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-user-management-service:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-user-management-service:${ccw-user-management-service.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Che
ss-World\ccw-user-management-service\pom.xml, line 14, column 14
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.doubleat.ccw:ccw-user-management-service-contract:jar:1.0
[WARNING] 'version' contains an expression but should be a constant. @ com.doubleat.ccw:ccw-user-management-service-contract:${ccw-user-management-service-contract.version}, F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess
-World\Chinese-Chess-World\ccw-user-management-service-contract\pom.xml, line 14, column 14
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] ccw-platform                                                       [pom]
[INFO] ccw-common                                                         [jar]
[INFO] ccw-config-service                                                 [jar]
[INFO] ccw-game-service-contract                                          [jar]
[INFO] ccw-game-service                                                   [jar]
[INFO] ccw-user-management-service-contract                               [jar]
[INFO] ccw-user-management-service                                        [jar]
[INFO]
[INFO] -------------------< com.doubleat.ccw:ccw-platform >--------------------
[INFO] Building ccw-platform 1.0                                          [1/7]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ ccw-platform ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ ccw-platform ---
[INFO] Installing F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\pom.xml to C:\Users\Admin\.m2\repository\com\doubleat\ccw\ccw-platform\1.0\ccw-platform-1.0.pom
[INFO]
[INFO] --------------------< com.doubleat.ccw:ccw-common >---------------------
[INFO] Building ccw-common 1.0                                            [2/7]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ ccw-common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ccw-common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ ccw-common ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ ccw-common ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ccw-common ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ ccw-common ---
[INFO] Building jar: F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\target\ccw-common-1.0.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ ccw-common ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ ccw-common ---
[INFO] Installing F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\target\ccw-common-1.0.jar to C:\Users\Admin\.m2\repository\com\doubleat\ccw\ccw-common\1.0\ccw-common-1.0.jar
[INFO] Installing F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-common\pom.xml to C:\Users\Admin\.m2\repository\com\doubleat\ccw\ccw-common\1.0\ccw-common-1.0.pom
[INFO]
[INFO] ----------------< com.doubleat.ccw:ccw-config-service >-----------------
[INFO] Building ccw-config-service 1.0                                    [3/7]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ ccw-config-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 2 resources
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ccw-config-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-config-service\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:testResources (default-testResources) @ ccw-config-service ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ ccw-config-service ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ ccw-config-service ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ ccw-config-service ---
[INFO] Building jar: F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-config-service\target\ccw-config-service-1.0.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ ccw-config-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ ccw-config-service ---
[INFO] Installing F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-config-service\target\ccw-config-service-1.0.jar to C:\Users\Admin\.m2\repository\com\doubleat\ccw\ccw-config-service\1.0\ccw
-config-service-1.0.jar
[INFO] Installing F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-config-service\pom.xml to C:\Users\Admin\.m2\repository\com\doubleat\ccw\ccw-config-service\1.0\ccw-config-service-1.0.pom
[INFO]
[INFO] -------------< com.doubleat.ccw:ccw-game-service-contract >-------------
[INFO] Building ccw-game-service-contract 1.0                             [4/7]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.2.0:resources (default-resources) @ ccw-game-service-contract ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Using 'UTF-8' encoding to copy filtered properties files.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ ccw-game-service-contract ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to F:\Workspace\Chinese-Chess-World\Public-Repo\Chinese-Chess-World\Chinese-Chess-World\ccw-game-service-contract\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /F:/Workspace/Chinese-Chess-World/Public-Repo/Chinese-Chess-World/Chinese-Chess-World/ccw-game-service-contract/src/main/java/com/doubleat/ccw/usermanagement/CcwGameServiceContractApplication.java:[3,40] package com.doubleat
.ccw.common.constant does not exist
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for ccw-platform 1.0:
[INFO]
[INFO] ccw-platform ....................................... SUCCESS [  0.479 s]
[INFO] ccw-common ......................................... SUCCESS [  2.070 s]
[INFO] ccw-config-service ................................. SUCCESS [  0.585 s]
[INFO] ccw-game-service-contract .......................... FAILURE [  0.666 s]
[INFO] ccw-game-service ................................... SKIPPED
[INFO] ccw-user-management-service-contract ............... SKIPPED
[INFO] ccw-user-management-service ........................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  4.110 s
[INFO] Finished at: 2021-02-27T19:21:18+07:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ccw-game-service-contract: Compilation failure
[ERROR] /F:/Workspace/Chinese-Chess-World/Public-Repo/Chinese-Chess-World/Chinese-Chess-World/ccw-game-service-contract/src/main/java/com/doubleat/ccw/usermanagement/CcwGameServiceContractApplication.java:[3,40] package com.doubleat
.ccw.common.constant does not exist
[ERROR]
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ccw-game-service-contract: Compilation failure
/F:/Workspace/Chinese-Chess-World/Public-Repo/Chinese-Chess-World/Chinese-Chess-World/ccw-game-service-contract/src/main/java/com/doubleat/ccw/usermanagement/CcwGameServiceContractApplication.java:[3,40] package com.doubleat.ccw.com
mon.constant does not exist

【问题讨论】:

  • 也许你忘了&lt;module&gt;someChild&lt;/module&gt; ?? ;)
  • 和 3 个(完全)不同(&独立)的东西:-目录结构,-pom 继承,-multi-module(按照惯例,我们(至少我)认为它们都是一样的,但是你 可以用这些 3 做疯狂的事情。)
  • 请发布 Maven 的完整输出。你碰巧在 ccw-game-service-contract 之前为模块运行 spring-boot-maven-plugin 吗?
  • 正如您所写的I always must be run mvn compile before can run mvn package or mvn install.,这表明您的构建结构/依赖项完全错误...该项目在 Github 等上可用吗?
  • @khmarbaise。它在这里github.com/Puskin2911/Chinese-Chess-World

标签: java spring-boot maven spring-boot-maven-plugin


【解决方案1】:

问题诊断

spring-boot-maven-plugin 为项目中的每个模块执行,如 Maven 输出中的以下行所证明:

[INFO] --- spring-boot-maven-plugin:2.4.3:repackage (repackage) @ ccw-game-service-contract ---
[INFO] Replacing main artifact with repackaged archive

此类模块的 JAR 工件不是通常的库,而是按照 Spring Boot documentation 中所述打包的可执行 JAR

该可执行 JAR 不适合 Java 编译器或任何其他基于 JVM 的语言的编译器使用。


解决方案

只有代表项目最终可执行工件的 Maven 模块才应该包含对spring-boot-maven-plugin 的调用。

您可以查看 Spring Boot 的官方指南 - Creating a Multi Module Project - 以获取分步指南和说明。

【讨论】:

  • 感谢分享
  • 还有一件事!我设计了一个基于spring cloud和spring boot的微服务。通过契约服务一起进行服务通信。这是很好的设计,对吧?或者任何解决方案,模式,你能告诉我吗?谢谢你
  • 很抱歉,如果您不了解和/或不了解您的业务背景和目标,无法用 600 个字符对这个问题给出有意义的答案。
猜你喜欢
  • 2012-07-05
  • 1970-01-01
  • 2015-03-21
  • 1970-01-01
  • 1970-01-01
  • 2016-09-24
  • 2015-10-21
  • 2021-06-25
  • 2016-10-27
相关资源
最近更新 更多