【发布时间】:2020-11-20 03:16:24
【问题描述】:
我有一个 Maven Spring Boot 微服务 Java 项目,它被安排成一个父模块和 6 个子模块。在父 pom.xml 中,我在 build/plugins 部分包含了 Maven Spring Boot 插件:-
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.5.RELEASE</version>
</plugin>
我的 6 个子模块中有 5 个是微服务,上面的插件确保在我运行 mvn clean install 时将这些构建到可执行的 Spring Boot jar 中,包括所有依赖项
但是,另一个子模块只是一个标准的 Java 实用程序项目,没有 Spring Boot 上下文。当我尝试构建时,我看到以下错误:-
Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.1.5.RELEASE:repackage failed: Unable to find main class -> [Help 1]
这是预期的,因为该子模块不是 Spring Boot 应用程序并且没有主类。我试图通过覆盖该子模块的 pom 文件中的 Spring Boot Maven 插件来解决此问题,以便将其视为标准的“瘦”jar:-
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<!-- The following enables the "thin jar" deployment option. -->
<!-- This creates a normal jar, not an executable springboot jar -->
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.11.RELEASE</version>
</dependency>
</dependencies>
</plugin>
但是,我在 Maven 构建中仍然看到完全相同的错误。我将不胜感激任何关于这个的提示或指示。
【问题讨论】:
-
听起来您根本不希望 Spring 插件在该模块中运行,因此您可以使用标准 Maven 编译器插件。在这种情况下,您可以将 Spring 插件绑定到阶段
none以禁用该模块,如 stackoverflow.com/questions/7821152/… 中所述 -
@Michael 非常感谢您的建议。我正在试一试。还没有运气,我不确定将什么指定为执行/ID。我会继续挖掘和尝试!
-
可以是任意的。只需在父级别给它一些 ID,“jons-magic-plugin”,然后在子级中重用相同的 ID。
-
@Michael Great - 这也有效,下面的解决方案也是如此。非常感谢,现在银行有两种可能的解决方案! :)
标签: java spring-boot maven