How to add programmatically dependencies to Gradle configuration?

This should do the trick:

configuration.getDependencies().add(dependenyMock);

@Test
void shouldGetFamilyDependenciesAcrossAllConfigurations() {
    final expected = ['subproject-0', 'subproject-1']

    final Project project = ProjectBuilder.builder().build()
    final configurations = project.getConfigurations()

    configurations.create('configuration-0')
    final Project subproject0 = ProjectBuilder.builder().withName(expected[0]).build()
    project.dependencies {
        delegate.'configuration-0'(subproject0)
    }

    configurations.create('configuration-1')
    final Project subproject1 = ProjectBuilder.builder().withName(expected[1]).build()
    project.dependencies {
        delegate.'configuration-1'(subproject1)
    }

    final actual = RestorePublishedArtifactTask.getFamilyDependencies(configurations)

    assertThat(actual, hasItems(expected.toArray(new String[expected.size()])))
}

Try to do it in this way:

project.getDependencies().add('compile', project(':common-configuration'))

compile - a name of the configuration
:common-configuration - a name of the project to add (or any other dependencies)

Tags:

Gradle