首页 > 解决方案 > 等价于 gradle 中测试依赖的 api

问题描述

这个问题已经发布了等同于 api for test dependency in gradle?但我没有看到任何解决方案。

我们几乎没有声明如下的依赖项

dependencies {
    testImplementation 'org.apache.curator:curator-test:4.2.0'
    testImplementation 'org.apache.curator:curator-framework:4.2.0'
}

我们希望将这些公开给这个库的消费者。由于它是 testImplementation,因此消费者需要显式声明我们想要避免的这些依赖项。

所以我希望将testImplementation更改为它的 api 等效项。但我在文档中找不到任何内容https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph

标签: gradledependency-management

解决方案


所以我希望将testImplementation更改为它的 api 等效项。但我在文档中没有找到

没有等效项,并且测试依赖项应该与主库模块分开。您将创建一个专门用于测试的单独的已发布库。这正是 Spring 项目所做的。

例如,Spring Boot 的测试库具有所有必要的测试依赖项apihttps ://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-starters/spring -boot-starter-test/build.gradle


推荐阅读