configurations {
    compile
    runtime { extendsFrom compile }
}
dependencies {
    repositories {
        ivy {
            artifactPattern projectDir.absolutePath + '/[artifact]-[revision].jar'
            ivyPattern projectDir.absolutePath + '/[module]-[revision]-ivy.xml'
            ivyPattern projectDir.absolutePath + '/[module]-[revision]-ivy.xml'
        }
    }
    compile group: 'test', name: 'projectA', version: '1.2', configuration: 'api'
    runtime group: 'test', name: 'projectA', version: '1.2'
    runtime group: 'test', name: 'projectB', version: '1.5', configuration: 'extraRuntime'
}

file("projectA-1.2.jar").text = ''
file("projectB-1.5.jar").text = ''
file("projectB-api-1.5.jar").text = ''
file("projectB-extraRuntime-1.5.jar").text = ''

defaultTasks 'listJars'

task listJars << {
    def compile = configurations.compile

    Set jars = compile.collect { it.name } as Set
    assert ['projectA-1.2.jar', 'projectB-api-1.5.jar'] as Set == jars

    def projectA = compile.resolvedConfiguration.firstLevelModuleDependencies.find { it.moduleName == 'projectA' && it.configuration == 'api' }
    def root = (projectA.parents as List)[0]
    def artifacts = projectA.getAllArtifacts(root).collect { it.name } as Set
    assert ['projectA', 'projectB-api'] as Set == artifacts

    def projectB = projectA.children.find { it.moduleName == 'projectB' && it.configuration == 'compileTime' }
    artifacts = projectB.getAllArtifacts(projectA).collect { it.name } as Set
    assert ['projectB-api'] as Set == artifacts

    def runtime = configurations.runtime

    jars = runtime.collect { it.name } as Set
    assert ['projectA-1.2.jar', 'projectB-api-1.5.jar', 'projectB-1.5.jar', 'projectB-extraRuntime-1.5.jar'] as Set == jars

    projectA = runtime.resolvedConfiguration.firstLevelModuleDependencies.find { it.moduleName == 'projectA' && it.configuration == 'api' }
    root = (projectA.parents as List)[0]
    artifacts = projectA.getAllArtifacts(root).collect { it.name } as Set
    assert ['projectA', 'projectB-api'] as Set == artifacts

    projectA = runtime.resolvedConfiguration.firstLevelModuleDependencies.find { it.moduleName == 'projectA' && it.configuration == 'default' }
    root = (projectA.parents as List)[0]
    artifacts = projectA.getAllArtifacts(root).collect { it.name } as Set
    assert ['projectA', 'projectB'] as Set == artifacts

    projectB = runtime.resolvedConfiguration.firstLevelModuleDependencies.find { it.moduleName == 'projectB' && it.configuration == 'extraRuntime' }
    artifacts = projectB.getAllArtifacts(root).collect { it.name } as Set
    assert ['projectB', 'projectB-extraRuntime'] as Set == artifacts
}