Gradle 测试依赖 [英] Gradle Test Dependency

查看:37
本文介绍了Gradle 测试依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目,项目 A 和项目 B.两者都是用 groovy 编写的,并使用 gradle 作为它们的构建系统.

I have two projects, project A and Project B. Both are written in groovy and use gradle as their build system.

项目 A 需要项目 B.这适用于编译和测试代码.

Project A requires project B. This holds for both the compile and test code.

如何配置A项目的测试类可以访问B项目的测试类?

How can I configure that the test classes of project A have access to the test classes of project B?

推荐答案

您可以通过测试"配置公开测试类,然后在该配置上定义 testCompile 依赖项.

You can expose the test classes via a 'tests' configuration and then define a testCompile dependency on that configuration.

我为所有 Java 项目设置了这个块,它包含所有测试代码:

I have this block for all java projects, which jars all test code:

task testJar(type: Jar, dependsOn: testClasses) {
    baseName = "test-${project.archivesBaseName}"
    from sourceSets.test.output
}

configurations {
    tests
}

artifacts {
    tests testJar
}

然后当我有测试代码时,我想在我使用的项目之间访问

Then when I have test code I want to access between projects I use

dependencies {
    testCompile project(path: ':aProject', configuration: 'tests')
}

这是针对Java的;我假设它也适用于 groovy.

This is for Java; I'm assuming it should work for groovy as well.

这篇关于Gradle 测试依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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