简体   繁体   English

Gradle 依赖项目 test-jar

[英]Gradle dependency project test-jar

I have a multi-module gradle project and I want to make use of some of the test classes from the shared module in my dependent module.我有一个多模块 gradle 项目,我想在我的依赖模块中使用共享模块中的一些测试类。

dependencies {
    compile project(':shared-module')

    testCompile project(':shared-module'), classifier: 'test-jar'
}

The first dependency works, but the testCompile dependency does not work.第一个依赖项有效,但 testCompile 依赖项不起作用。 I cannot seem to find the syntax for it.我似乎找不到它的语法。 The maven equivalent would be: Maven 等效项是:

<dependency>
    <groupId>${project.groupId}</groupId>
    <artifactId>shared-module</artifactId>
    <version>${project.version}</version>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>

You can do你可以做

dependencies {
    compile project(':shared-module')
    testCompile project(path: ':shared-module', configuration: 'testRuntime') 
} 

You could use the nebula test jar plugin你可以使用 nebula 测试 jar 插件

Note Nebula have deprecated this plugin as they believe test utilities should live in their own project.注意Nebula 已弃用此插件,因为他们认为测试实用程序应该存在于他们自己的项目中。 I tend to agree with them我倾向于同意他们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM