如何在不重建项目的情况下在Gitlab CI中进行Maven测试?
我创建了一个Maven Spring Boot项目。在构建工作中,我只想在没有测试的情况下构建项目。在测试阶段,我想运行单元测试并使用构建阶段的构建,因此在测试阶段没有新的构建。问题是MVN在测试阶段再次运行构建。
image: maven:3.8-jdk-11
stages:
- build
- test
build-job:
stage: build
script:
- mvn compile
artifacts:
paths:
- target
test-job:
stage: test
script:
- mvn test
如果它再次在测试阶段运行构建,则无需构建阶段。但是,我希望两者都可以分开阶段,以更好地分开并查看出现问题的地方。
I created a Maven Spring boot project. In the build job I want to only build the project without tests. In the test stage I want to run unit tests and use the build from the build stage, so no new build in test stage. The problem is that mvn runs a build again in the test stage.
image: maven:3.8-jdk-11
stages:
- build
- test
build-job:
stage: build
script:
- mvn compile
artifacts:
paths:
- target
test-job:
stage: test
script:
- mvn test
If it runs a build in the test stage again, then the build stage wouldnt be necessary. But I want separate stages for both to better separate and see where something goes wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
起初,我认为将构建过程分为不同阶段的想法看起来很有吸引力,但实际上没有任何实际好处,尤其是在您试图将包装分组为编译,测试以及可能的包装阶段时。考虑以下内容:
答案 上面提到的已经被Maven涵盖了 - 没有实际的理由将
MVN软件包
分为单独的部分,此外,Maven项目中的所有内容verify 阶段仅是关于代码-CI -CI不应干预
MVN软件包
。现在,为什么我们需要CI中的阶段?显然,当我们的CI流程以某种方式取决于环境时,即当我们在不同平台上执行构建或我们想运行外部工具时,我们需要阶段,但是没有外部工具的位置,直到
阶段
。
第二,如果您真的想将
mvn软件包
分为单独的阶段,则选项如下:-dmaven.main.skip = true
来命令行或设置诸如< skipmain> my.cool.property</skipmain>
and code and code-dmy.cool.property = true
MVN Resources:testResources Compiler:testCompile:testCompile compiler:testCompile nurefire:测试
但是,从我的角度来看,所有这些选项看起来都很差:由于以下考虑因素:
At first, in my opinion the idea to split build process into different stages might look attractive but actually does not have any practical benefits, especially in your case when you are trying to split packaging into compile, test and, probably, package stages. Think about following:
Everything mentioned above is already covered by maven - there is no practical reason to split
mvn package
into separate parts, moreover everything in maven project tillverify
phase is about the code only - CI should not intervene inmvn package
.Now, why do we need stages in CI? Obviously we need stages when our CI process somehow depends on environment, i.e. when we are performing build against different platforms or we would like to run external tools, however there is no place for external tools till
verify
phase.At second, if you really want to split
mvn package
into separate stages the options are following:-Dmaven.main.skip=true
to command line or setup something like<skipMain>my.cool.property</skipMain>
and pass-Dmy.cool.property=true
mvn resources:testResources compiler:testCompile surefire:test
However, all of those options look very poor from my perspective due to following considerations: