具有Spring-Boot-Starter-Parent的多模块Maven项目结构

时间:2017-02-16 18:49:49

标签: java spring maven spring-mvc

好的,我会直接进入它。我有一个使用spring的多模块maven项目。项目结构可以概括为:

Project Root
|--common module
|----src
|----pom.xml
|--module 1
|----src
|----pom.xml
|--module 2
|----src
|----pom.xml
|-pom.xml

在这种情况下,我将root-level 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也具有共同模块作为依赖性。当尝试在本地运行时,我在公共模块上使用mvn install,以便我可以运行其他两个模块。问题是,当我在共同运行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. 我可以分离出依赖关系,因此模块1和模块2将spring-boot-starter-parent作为其父级,并从根pom中删除spring-boot-starter,从而释放常用。

  2. 我可以删除root pom作为common的common。

  3. 我可以手动构建spring-boot-starter在项目中所做的一切。

  4. 这些选项中哪一个是最好的,还是有一个我没有看到的选项更可取?

1 个答案:

答案 0 :(得分:1)

Spring-boot有maven build plugin。如果它包含在你的pom中。删除它并尝试。

相关问题