如何在 testCompile 和 test 阶段之间(在 Surefire 执行之前)执行 Maven 的 antrun?

Edy*_*rne 2 java maven-3 maven maven-surefire-plugin maven-antrun-plugin

在我的 Maven 构建中,我有一小块 Ant 代码需要在 Surefire 开始执行一些配置之前运行。

代码是用antrun执行的,但是我不能在Surefire之前让antrun被执行。

这是我的构建输出的相关部分:

[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ com...tests ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to C:\...\com...tests\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.16:test (default-test) @ com...tests ---
[INFO] Surefire report directory: C:\...\com...tests\target\surefire-reports
Run Code Online (Sandbox Code Playgroud)

基本上我需要 antrun 在maven-compiler-plugin:3.1:testCompile和之间执行maven-surefire-plugin:2.16:test

我尝试将antrun绑定到测试阶段并将其放在POM文件中的surefire插件之前,但它总是在Surefire插件之后执行。我还尝试将它配置为在 testCompile 阶段运行,并将其放在 maven-compiler-plugin 插件之后,但也没有成功......它在surefire之后执行。

有谁知道如何让它在这两者之间执行?

谢谢!

爱德华多

Ori*_*Dar 5

您可以在process-test-classes生命周期阶段执行 antrun 插件,该阶段就在test-compiletest


khm*_*ise 5

如果您查看构建生命周期,您会发现 compile/testCompile 和 test 之间有几个步骤...

compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy
Run Code Online (Sandbox Code Playgroud)

所以我建议process-test-classes在你的情况下使用这正是你需要的。