Q:

Gradle dependency for compile time only and test

I am basically looking for a way to mimic the maven dependency provided. I am building a jar (an extension to a db driver), which depends on another jar (the db driver), but I do not want to include that jar.
I am able to use compileOnly to achieve that, however now the tests won't run or compile as the required jar is not included in tests.
I tried through the list of available dependencies like testCompile, however I could not find one that makes the jar available at compile time and when the tests run and compile.
How would I include that jar properly?
Edit: As requested, the build.gradle file:
group 'com.mygroup'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compileOnly "org.mongodb:mongodb-driver:3.3.0"
    testCompile "org.mongodb:mongodb-driver:3.3.0"
}

Listing the dependency twice does work, however obviously is not a very nice solution

A:

You can extend your testCompile configuration from the compileOnly configuration:
configurations {
    testCompile.extendsFrom compileOnly
}

