2013-09-24 29 views
5

は、私は次のコードを持っている:プログラムで依存関係をGradle構成に追加するにはどうすればよいですか?

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

答えて

2
@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()]))) 
} 
4

は、これはトリックを行う必要があります。

configuration.getDependencies().add(dependenyMock); 
+0

を '()'を追加どのように私はに渡すことができ、依存関係にsubproject0を回すのですか? –

関連する問題