等价于gradle中的测试依赖关系的api? [英] Equivalent of api for test dependency in gradle?

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

问题描述

我正在执行多模块gradle项目。在我的一个模块中,我具有api依赖项:

I'm having multi module gradle project. In one of my modules I'm having api dependency:

api('de.flapdoodle.embed:de.flapdoodle.embed.mongo')

我想将其更改为在所有模块中的测试中可见的依赖项。有 testImplementation 依赖性,但没有 testApi

I want to change it to dependency that will be visible in tests, across all modules. There is a testImplementation dependency but there is no testApi.

因为我想使用真实的mongo实例而不是嵌入式实例,所以我不再对生产类路径具有这种依赖性。另一方面,我在依赖数据访问的不同模块中进行测试-在那种情况下,我想在测试类路径上使用嵌入式mongo运行那些测试。

I cannot have this dependency on production classpath anymore since I want to use real mongo instance instead of embedded one. On the other hand I have tests in different modules that depend on data access - in that case I want to run those test with embedded mongo on test classpath.

我该如何使此依赖性在所有模块测试中可见?

How I can make this dependency visible in all modules tests?

推荐答案

问题(向我显示)是在一个模块中的各个模块之间共享测试代码多模块项目

The question (appears to me) is sharing the test code across modules in a multi-module project

简短的回答-否-模块之间存在直接的测试依赖关系共享。

Short answer - No - there is direct test dependency share across modules.

通过构建设置在模块之间内部共享测试代码

To share test code between modules internally via build settings

官方gradle路由 https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures

简单的黑客攻击

testImplementation files(project(':core-module').sourceSets.test.output.classesDirs)

将以上行添加到ind通常,在您需要的地方或带有 subprojects()且具有适当条件的地方

add the above line either individually where you need or in root with subprojects() with appropriate condition

*还有其他可能的路线*

ex:通过配置
child.testImplementation扩展parent.testImplementation(或运行时)

*there are other possible routes as well *
ex: via configuration child.testImplementation extends parent.testImplementation (or runtime)

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

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