【发布时间】:2017-07-06 01:20:36
【问题描述】:
好的,我会直接进入它。我有一个使用 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 也有共同的模块作为依赖。尝试在本地运行时,我在公共模块上使用 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。
我可以将根 pom 作为公用的父级删除。
我可以手动构建 spring-boot-starter 在项目中所做的一切。
这些选项中的哪一个是最好的,或者有没有我认为更可取的选项?
【问题讨论】:
标签: java spring maven spring-mvc