Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of api for test dependency in gradle?

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')

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.

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?

like image 725
pixel Avatar asked Sep 21 '18 09:09

pixel


1 Answers

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

Official gradle route https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures

Simple hack

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

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

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

like image 84
PrasadU Avatar answered Sep 28 '22 17:09

PrasadU