好的,我就直接开始吧。我有一个使用 spring 的多模块 Maven 项目。项目结构可以概括如下:
Project Root
|--common module
|----src
|----pom.xml
|--module 1
|----src
|----pom.xml
|--module 2
|----src
|----pom.xml
|-pom.xml
在本例中,我有根级别的 pom 文件,将 spring-boot-starter 声明为父级:
<groupId>com.example.stackoverflow</groupId>
<artifactId>indania-jones</artifactId>
<version>VersionNumber</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
</parent>
子模块将根 pom 作为其父模块。
<parent>
<groupId>com.example.stackoverflow</groupId>
<artifactId>indiana-jones</artifactId>
<version>VersionNumber</version>
</parent>
<artifactId>module-1</artifactId>
在这种简化的情况下,模块 1 和模块 2 也具有公共(public)模块作为依赖项。当尝试在本地运行时,我在公共(public)模块上使用 mvn install ,以便可以运行其他两个模块。问题是,当我在 common 上运行 mvn install 时,它失败了。
[ERROR] Failed to execute goal org.springframework.boot:spring-boot- maven-plugin:1.3.2.RELEASE:repackage (default) on project q-common: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.3.2.RELEASE:repackage failed: Unable to find main class -> [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/PluginExecutionException
看起来 spring-boot-starter-parent 的 pom 正在执行我不想执行的额外职责。
如果您需要了解原因和内容,这些模块是特定的 REST 服务,通用模块包含它们共同的共享 DTO 和持久性对象。在我看来,我有几个选择:
我可以分离出依赖项,以便模块 1 和模块 2 将 spring-boot-starter-parent 作为其父级,并从根 pom 中删除 spring-boot-starter,从而释放 common.xml。
我可以删除 root pom 作为 common 的父级。
我可以手动构建 spring-boot-starter 在项目中执行的所有操作。
这些选项中哪一个是最好的,或者是否有一个我没有看到的更好的选项?
最佳答案
Spring-boot 有 Maven 构建 plugin 。如果它包含在你的 pom.xml 中删除它并尝试。
关于java - 带有 Spring-Boot-Starter-Parent 的多模块 Maven 项目结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42282280/