多模块项目的 Maven 配置
Posted
技术标签:
【中文标题】多模块项目的 Maven 配置【英文标题】:Maven configuration for Multi Module Project 【发布时间】:2017-09-21 12:54:39 【问题描述】:我正在使用 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$
【问题讨论】:
mvn -N io.takari:maven:wrapper
是什么意思?
【参考方案1】:
您需要有一个pom.xml
文件才能运行./mvnw clean install
。
[错误] 您指定的目标需要执行项目,但此目录中没有 POM (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example )。
查看教程中的多模块项目的 Maven 配置和库的 Maven 配置。在那里你会找到必要的pom.xml
文件。
【讨论】:
这是我的想法,但阅读指南后我将实现目标,然后添加 pom.xml 文件【参考方案2】:有两件事:
要运行任何 maven 项目,最基本的首要要求是您必须拥有 pom.xml
。缺少此文件会引发错误:
[错误] 你指定的目标需要一个项目来执行,但那里 此目录中没有 POM (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example)。 请确认您从正确的目录调用了 Maven。 -> [帮助 1]
教程https://spring.io/guides/gs/multi-module/#scratch中提到你应该有pom.xml
文件,请参考本节▶Maven多模块项目配置
【讨论】:
以上是关于多模块项目的 Maven 配置的主要内容,如果未能解决你的问题,请参考以下文章
是否可以从 Maven 多模块项目的父模块中的配置文件夹加载 Spring-Boot 属性?