0

I have two Gradle subprojects which use java plugin. It defines typical main, test, etc SourceSets.

Output of this task seems superimposed. I expected to see a source set per sub-project. Does Gradle scope SourceSet using sub-project name or it is one global collection? How do you refer to a sourceset in project A?

task report {
 doLast{
    sourcesets.findAll().each { srcset ->
        println srcset.name
        println "src: " srcset.java.srcDirs
    }
  }
}
Vortex
  • 789
  • 12
  • 21
  • 1
    In a gradle file, method calls are used implicitly on the "project" object, meaning, "task report {...}" is equivalent to "project.task('report', {})", where "project" refers to the given subproject to which the gradle file belongs. Within closures like "doLast", the context object is typically "project" as well. So sourceSets, refer to the sourceSets of the given subproject whose build.gradle you use this snippet in. Referring to other subprojects might be possible, but breaks build hygiene, and can have undesirable consequences. – tkruse Jan 20 '20 at 06:36
  • @tkruse, thank you – Vortex Jan 20 '20 at 16:08

0 Answers0