Android gradle androidTestApi & testApi configuration obsoleted

前端 未结 2 952
野性不改
野性不改 2021-02-19 19:53

I got 2 modules, module A and module B. Module B depends on module A, module A shares dependency libraries to module B by using api configuration.

When set

相关标签:
2条回答
  • 2021-02-19 20:07

    The way I did this was by creating a custom configuration. In your case inside the build.gradle file module A add:

    configurations {
        yourTestDependencies.extendsFrom testImplementation
    }
    
    dependencies {
        // example test dependency
        testImplementation "junit:junit:4.12"
        // .. other testImplementation dependencies here
    }
    

    And in the build.gradle of module B add:

    dependencies {
        testImplementation project(path: ':moduleA', configuration: 'yourTestDependencies')
    }
    

    The above will include all testImplementation dependencies declared in module A to module B.

    0 讨论(0)
  • 2021-02-19 20:29

    This is Chris Margonis (Kudos!) answer in Kotlin-DSL:

    // "base" module/project
    configurations {
        create("testDependencies"){
            extendsFrom(configurations.testImplementation.get())
        }
    }
    
    dependencies {
        // example test dependency
        testImplementation "junit:junit:4.12"
        // .. other testImplementation dependencies here
    }
    
    //another module
    dependencies {
        testImplementation(project(path = ":base", configuration = "testDependencies"))
    }
    
    0 讨论(0)
提交回复
热议问题