当前位置 : 主页 > 手机开发 > 其它 >

如何以编程方式将依赖项添加到Gradle配置?

来源:互联网 收集:自由互联 发布时间:2021-06-22
我有以下代码: static def getFamilyDependencies(ConfigurationContainer configurations) { def result = configurations.collect { configuration - configuration.allDependencies.findAll { dependency - dependency instanceof DefaultProjectD
我有以下代码:

static def getFamilyDependencies(ConfigurationContainer configurations) {
    def result = configurations.collect { configuration ->
        configuration.allDependencies.findAll { dependency ->
            dependency instanceof DefaultProjectDependency
        } collect { projectDependency ->
            projectDependency.dependencyProject.name
        }
    } flatten()

    result as Set
}

我想测试一下.到目前为止,我有:

@Test
void shouldGetFamilyDependencies() {
    final Project project = ProjectBuilder.builder().build()

    final configurations = project.getConfigurations()

    configurations.create('configuration0')
    configurations.create('configuration1')

    configurations.each { configuration ->
        println "***************** ${configuration}"

        configuration.allDependencies.each {
            println "@@@@@@@@@@@@@@@@@ ${it}"
        }
    }
}

如何向配置添加依赖项?以下不起作用:

final Project subproject = ProjectBuilder.builder().build()
    configurations.configuration0 {
        subproject
    }
    configurations.configuration1 {
        allDependencies {
            subproject
        }
    }
这应该做的伎俩:

configuration.getDependencies().add(dependenyMock);
网友评论