如何将args传递给使用Gradle运行测试的JVM [英] How to pass args to JVM which runs tests with Gradle

查看:127
本文介绍了如何将args传递给使用Gradle运行测试的JVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Gradle的新秀,我不确定Gradle在运行测试集时是否会启动新的JVM.

I am a Gradle rookie and I am not sure whether Gradle will start the new JVM when it runs the test set.

将JVM参数传递给Gradle测试任务,我想将一些参数传递给运行测试集的JVM.

Like Passing JVM arguments to Gradle test task I want to pass some parameters to the JVM running the test set.

我在 build.gradle 中添加了以下几行:

I added the following lines to build.gradle:

...
test {
    groovy {
        jvmArgs '-agentpath:/usr/lib/code_dependency_capturer.so' // add line
        srcDirs = ['src/test']
        if (!JavaVersion.current().isJava8Compatible()) {
            exclude '**/v8/*'
            exclude '**/vm8/*'
        }
    }
    resources {
        srcDirs = ['src/test-resources']
    }
}
...

但是它告诉我:

A problem occurred evaluating root project 'groovy'.
Could not find method jvmArgs() for arguments[-agentpath:/usr/lib/code_dependency_capturer.so] on source set 'test' of type org.gradle.api.internal.tasks.DefaultSourceSet. 

我搜索了此错误,但未能解决.

I googled this error but failed to solve it.

推荐答案

尝试设置封闭的test任务的jvmArgs,而不是尝试在groovy上进行设置.

Try setting the jvmArgs of the enclosing test task rather than trying to set them on groovy.

您收到的错误提示groovy上不存在jvmArgs.

The error you are getting suggests that jvmArgs isn’t present on groovy.

示例:

...
test {
    jvmArgs '-agentpath:/usr/lib/code_dependency_capturer.so' // add line
    groovy {      
        srcDirs = ['src/test']
        ...
    }
    ...
}

这只是一个猜测,因为我没有方便进行确认的gradle设置,但值得一试,因为jvmArgs被记录为test的属性:

This is just a guess as I don’t have a gradle setup handy on which to confirm but worth a try as jvmArgs is documented as a property for test:

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:jvmArgs

List<String> jvmArgs

用于为进程启动JVM的额外参数.不包括系统属性和最小/最大堆大小.

The extra arguments to use to launch the JVM for the process. Does not include system properties and the minimum/maximum heap size.

由于jvmArgs是String的列表,因此您可以向其传递多个参数,请参阅:

Since jvmArgs is a list of String you can pass it multiple arguments, refer to:

http://docs.groovy- lang.org/next/html/documentation/working-with-collections.html#_list_literals

示例:

  jvmArgs ["-Xarg1", "-Xarg2"]

对于"-Dprop = value"系统属性,请使用test任务的systemProperties代替:

For "-Dprop=value" system properties use the systemProperties of the test task instead:

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:systemProperties

这篇关于如何将args传递给使用Gradle运行测试的JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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