【问题标题】:How to execute Maven's antrun between testCompile and test phases (before Surefire executes)?如何在 testCompile 和测试阶段(在 Surefire 执行之前)之间执行 Maven antrun?
【发布时间】:2014-02-11 11:54:16
【问题描述】:

在我的 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

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

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

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

谢谢!

爱德华多

【问题讨论】:

  • 您通过 Ant 做了哪些无法通过 Maven 完成的操作?你能告诉我们更多关于这部分的细节吗?
  • 在这种情况下,我正在更新一个属性文件。它可能在 Maven 中完成,但更新它的命令来自包含“sed”命令的文件,因此 antrun 似乎是读取该文件并在测试运行之前执行 sed 命令的最简单方法。
  • 为什么要更新属性文件,因为您在src/test/resources 中有第二组仅用于测试,而不会干扰src/main/resources 中的生产属性文件。
  • 属性文件需要来自构建的值(可能还有 Jenkins 的参数)。它不是静态的,所以我在运行测试之前进行更新。无论如何,感谢您指出:)

标签: java maven maven-3 maven-surefire-plugin maven-antrun-plugin


【解决方案1】:

你可以在process-test-classes生命周期阶段执行antrun插件,这个阶段正好在test-compiletest之间

【讨论】:

    【解决方案2】:

    如果您查看build life-cycle,您会发现 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
    

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

    【讨论】:

    • 不敢相信我错过了!我正在查看另一个未列出该阶段的 Maven 帮助页面!太感谢了! (必须先将另一个答案标记为正确,但要支持你的)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 2017-05-06
    • 1970-01-01
    • 2013-07-22
    相关资源
    最近更新 更多