我有一个使用 Spring Boot 的多模块 maven 应用程序:
- spring boot parent
- myproject parent (both parent and module pom)
- module1
- module2
- module-it (integration tests)
Run Code Online (Sandbox Code Playgroud)
在我的 module-it 中,我将其他模块添加到我的依赖项中,并按如下方式配置 maven-failsafe-plugin:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
当我用 maven 构建我的项目时,我得到“构建成功”:
mvn clean install
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好。
但是我希望我的每个模块在构建结束时都是一个可执行的 jar。使用上述设置,清单未定义且 jar 不可执行。为了解决这个问题,我在 module1 和 module2 pom 文件中添加了以下内容:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
有了这个设置,我的 jar 文件是可执行的,但我不能再构建了。我在我的模块中使用的类 - 它没有找到。
[ERROR] Failed …Run Code Online (Sandbox Code Playgroud)