多模块项目的 Maven 配置

Maven configuration for Multi Module Project

我正在使用 Spring Boot 创建一个多模块项目,该项目将有 3 个模块:moduleA、moduleB 和 moduleC。

我正在学习本教程https://spring.io/guides/gs/multi-module/#scratch

在根目录中我创建了 3 个目录:moduleA、moduleB 和 moduleC

我运行mvn -N io.takari:maven:wrapper

在我 运行 sudo ./mvnw 之后,这里是结果:

MacBook-Pro-de-calzada:multi-module-project-example nunito$ sudo ./mvnw
/Users/nunito/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.066 s
[INFO] Finished at: 2017-04-24T20:03:37+02:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[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/NoGoalSpecifiedException
MacBook-Pro-de-calzada:multi-module-project-example nunito$ 

并执行./mvnw clean install

/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.062 s
[INFO] Finished at: 2017-04-24T22:38:20+02:00
[INFO] Final Memory: 8M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example). Please verify you invoked Maven from the correct directory. -> [Help 1]
[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/MissingProjectException
MacBook-Pro-de-calzada:multi-module-project-example nunito$ 

您需要一个 pom.xml 文件才能 运行 ./mvnw clean install

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example).

查看教程中的 多模块项目的 Maven 配置 库的 Maven 配置 。在那里您会找到必要的 pom.xml 文件。

有两件事:

  1. 对于 运行 任何 Maven 项目,最基本和首要的要求是您必须有一个 pom.xml。缺少此文件将引发错误:

    [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example). Please verify you invoked Maven from the correct directory. -> [Help 1]

  2. 在教程https://spring.io/guides/gs/multi-module/#scratch中提到你应该有pom.xml文件,请参考本节▶Maven配置对于多模块项目