I have a multiple module gradle project.
I am trying to run DependencyReportTask for each subproject (actually for each allprojects)....and then concatenate to a single file.
If I do it like this:
allprojects {
/* create a .txt file for each subproject (and the root project */
task generateSingleProjectDependencies(type: DependencyReportTask) {
outputFile = file('singleproject.dependencies.txt')
}
}
task concatenateAllProjectsDependencyFiles {
doLast {
/* create a FileTree with all the subproject .txt files */
FileTree singleProjectsFileTree = fileTree('.') {
include 'singleproject.dependencies.txt'
}
if (singleProjectsFileTree.empty) {
println 'singleProjectsFileTree was empty'
} else {
copy {
println 'allprojects.dependencies.txt is being created, how many times did I fire?'
/* write out the multiple single-file-txts into a master .txt file */
def outputFileName = "allprojects.dependencies.txt"
def output = new File(outputFileName)
output.write('')
singleProjectsFileTree.each {
f -> output << f.text
}
}
}
}
}
/* use dependsOn to get the sequence correct */
concatenateAllProjectsDependencyFiles.dependsOn generateSingleProjectDependencies
/* now "finalize" the over-all "build" task..with our custom dependency-all task */
build.finalizedBy concatenateAllProjectsDependencyFiles
where "concatenateAllProjectsDependencyFiles" is OUTSIDE the "allprojects", I only get the root project's results.
(so that is not quite right) :(
===========
If I move concatenateAllProjectsDependencyFiles to inside the "allprojects"
allprojects {
/* create a .txt file for each subproject (and the root project */
task generateSingleProjectDependencies(type: DependencyReportTask) {
outputFile = file('singleproject.dependencies.txt')
}
task concatenateAllProjectsDependencyFiles {
doLast {
/* create a FileTree with all the subproject .txt files */
FileTree singleProjectsFileTree = fileTree('.') {
include 'singleproject.dependencies.txt'
}
if (singleProjectsFileTree.empty) {
println 'singleProjectsFileTree was empty'
} else {
copy {
println 'allprojects.dependencies.txt is being created, how many times did I fire?'
/* write out the multiple single-file-txts into a master .txt file */
def outputFileName = "allprojects.dependencies.txt"
def output = new File(outputFileName)
output.write('')
singleProjectsFileTree.each {
f -> output << f.text
}
}
}
}
}
/* use dependsOn to get the sequence correct */
concatenateAllProjectsDependencyFiles.dependsOn generateSingleProjectDependencies
/* now "finalize" the over-all "build" task..with our custom dependency-all task */
build.finalizedBy concatenateAllProjectsDependencyFiles
}
I get
allprojects.dependencies.txt is being created, how many times did I fire?
showing up N+1 times (N for subproject count plus one root project).
(so that is not quite right) :(
and it isn't just that is fires N+1 times, I get mixed results....maybe a thread race condition with the generation of the singleproject.dependencies.txt creation.
how can I get concatenateAllProjectsDependencyFiles to fire only once, and "find" all the subproject's "singleproject.dependencies.txt" files?