Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add provided dependency to test classpath using Gradle

I've provided dependency scope configured like below. My problem is, the provided dependencies are not visible during runtime in tests. How can I configure this to keep the dependencies provided but available on the test classpath?

apply plugin: 'java'

configurations {
    provided
}

sourceSets {
    main {
        compileClasspath += configurations.provided
    }
}

dependencies {
    provided 'com.google.guava:guava:18.0'
    provided 'org.apache.commons:commons-lang3:3.3.2'

    // Tests
    testCompile 'junit:junit:4.11'
    testCompile 'org.assertj:assertj-core:1.7.0'

    // Additional test compile dependencies
    testCompile 'joda-time:joda-time:2.2'
}

One solution is to add the dependency like the joda-time library with testCompile scope, but I don't want to duplicate any entries. I'm sure it can be achieved with proper configuration.

like image 780
tomrozb Avatar asked Nov 26 '25 20:11

tomrozb


1 Answers

Two ways to do this. First, have the testRuntime configuration extend from provided.

configurations {
    provided
    testRuntime.extendsFrom(provided)
}

Second, you could add the provided configuration to the classpath of your test task.

test {
    classpath += configurations.provided
}
like image 97
Mark Vieira Avatar answered Nov 28 '25 09:11

Mark Vieira