Get dependencies on a subproject inside the root project

Unable to get dependent subprojects in root assembly file. For some reason, they are not initialized. Is it possible to get a list of dependencies on project1 , for example, inside root ?

Pls see the copyToLib task . It should return values ​​from the dependencies section of project1 , but it really isn't.

Gradle version 2.0

Root
|
|-project1
|    |-build.gradle
|-project2
|    |-build.gradle
|-core1
|    |-build.gradle
|-core2
|    |-build.gradle
|-build.gradle
|-settings.gradle

      

settings.gradle

include 'project1','project2','core1','core2'
rootProject.name="Root"

      

project1: build.gradle

version = '0.1'
dependencies {
    compile project(':core1'),
            project(':core2'),
            'org.springframework:spring-web:4.0.6.RELEASE'
}

      

root: build.gradle

subprojects{
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply from: "${rootProject.projectDir}/eclipse.gradle"
    sourceCompatibility = 1.7
    repositories {
         mavenCentral()
    }
    task copyToLib(type: Copy) {
        def deps = project.configurations.compile.getAllDependencies().withType(ProjectDependency)
        for ( dep in deps ) {
            println dep.getDependencyProject().projectDir
        }
    }
    build.dependsOn(copyToLib)
}

      

+3


source to share


1 answer


When project

used in subprojects

, it refers to the current project β€” in this particular case β€” to root.

You need to remove the task addition from the subprojects

close and add the following piece of code:



subprojects.each { p ->
    configure(p) {
     task copyToLib << {
       def deps = p.configurations.compile.allDependencies.withType(ProjectDependency)
         for ( dep in deps ) {
           println dep.getDependencyProject().projectDir
         }
        }
        p.build.dependsOn(copyToLib)
    }
}

      

Simplified the task (it's not a type Copy

). You need to distinguish task action from configuration.

+1


source







All Articles