如何为ant junit命令提供条件jvmarg? [英] How can I provide a conditional jvmarg for the ant junit command?

查看:163
本文介绍了如何为ant junit命令提供条件jvmarg?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的商店在Java 6、7和8上设置了多个构建和测试环境(Jenkins,Ant 1.9.6).仅在Java 7上,为了使我们的测试成功运行,我们需要添加JVM参数-XX:-UseSplitVerifier.

Our shop has multiple build and test environments (Jenkins, Ant 1.9.6) set up on Java 6, 7 and 8. On Java 7 only, in order for our tests to run successfully, we need to add the JVM argument -XX:-UseSplitVerifier.

我不能在junit内使用condition,因此我在init任务中设置了布尔属性:

I can't use a condition inside junit, so I set a boolean property in the init task:

<condition property="usesplitverifier">
    <equals arg1="${ant.java.version}" arg2="1.7" />
</condition>

在我的test任务中,仅当该属性为true时,才需要将jvmarg添加到junit:

In my test task, I need to add jvmarg to junit only if that property is true:

<echo message="usesplitverifier: ${usesplitverifier}" />

<junit printsummary="yes" haltonfailure="no" fork="yes" forkmode="once" tempdir="${build.dir}">
    <jvmarg if="usesplitverifier" value="-XX:-UseSplitVerifier" />
    ...
</junit>

输出为:

        [echo] usesplitverifier: true

BUILD FAILED
C:\workspace\util\build.xml:141: jvmarg doesn't support the "if" attribute

我试图避免将 ant-contrib 添加到我们的构建/测试环境中.另外,我想避免向构建脚本中添加更多目标(我正在尝试简化构建过程).还有另一种方法可以在这里工作吗?

I'm trying to avoid adding ant-contrib to our build/test environment. Also, I'd like to avoid adding more targets to the build script (I'm trying to simplify the build process). Is there another approach that might work here?

推荐答案

在写这个问题时,我发现了解决方案另一个问题中的a>,由于过于含糊而被关闭.我决定发布此问题,以提供特定的用例.

While I was writing this question, I found the solution in another question that was closed as being too vague. I decided to post this question in order to provide a specific use case.

如果/除非命名空间可以在任何Ant命令中使用.就我而言,我需要在项目中添加if命名空间:

The if/unless namespaces may be used in any Ant command. In my case, I needed to add the if namespace to the project:

<project name="my-project" xmlns:if="ant:if" ...>

然后将条件放在jvmarg上,如下所示:

And then put the conditional on jvmarg as follows:

<junit printsummary="yes" haltonfailure="no" fork="yes" forkmode="once" tempdir="${build.dir}">
    <jvmarg if:set="usesplitverifier" value="-XX:-UseSplitVerifier" />
    ...
</junit>

在这种情况下if:set起作用的原因是,如果${ant.java.version}不是1.7,则该属性保持未设置状态.

The reason if:set works in this case is that if ${ant.java.version} is not 1.7, the property remains unset.

注意事项(在我的情况下是可以接受的):

Caveats (acceptable in my case):

  • if/unless名称空间仅在Ant 1.9.1起可用.
  • 在Ant 1.6之前,${ant.java.version}返回用于编译Ant的JVM版本.
  • The if/unless namespaces are only available since Ant 1.9.1.
  • Prior to Ant 1.6, ${ant.java.version} returns the version of the JVM that Ant was compiled with.

这篇关于如何为ant junit命令提供条件jvmarg?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆