Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add programmatically dependencies to Gradle configuration?

Tags:

gradle

I have the following code:

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
}

and I would like to test it. So far, I have:

@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}"
        }
    }
}

How do I add dependencies to the configurations? The following doesn't work:

    final Project subproject = ProjectBuilder.builder().build()
    configurations.configuration0 {
        subproject
    }
    configurations.configuration1 {
        allDependencies {
            subproject
        }
    }
like image 503
Noel Yap Avatar asked Sep 24 '13 21:09

Noel Yap


1 Answers

This should do the trick:

configuration.getDependencies().add(dependenyMock);
like image 184
Rene Groeschke Avatar answered Sep 25 '22 19:09

Rene Groeschke