Slackbot
08/08/2023, 8:49 PMSam Edwards
08/08/2023, 8:57 PMAdam
08/08/2023, 8:59 PMallProjects
.
val report by tasks.registering {
dependsOn(
// note: this is usually bad practice - see below
allprojects.map { otherProject ->
otherProject.task("collect")
}
)
}
However... even though it's easy to write and Gradle will let you do it, it's considered bad practice for a number of reasons. The 'better', but significantly more complicated, way is to use Configurations to share files.Zak Taccardi
08/08/2023, 9:00 PMdependencies { }
blockZak Taccardi
08/08/2023, 9:01 PMSam Edwards
08/08/2023, 9:16 PMallprojects
piece didn't seem to work (I know it's the wrong way):
private fun registerOnRootProject(rootProject: Project) {
val rootProjectFeatureUsageReportTask: TaskProvider<FeatureUsageReportTask> =
rootProject.tasks.register(
FeatureUsageReportTask.TASK_NAME,
FeatureUsageReportTask::class.java
) {
it.setParams(
project = rootProject
)
}
rootProject.allprojects.forEach { otherProject ->
val collectTask = otherProject.tasks.findByName(FeatureUsageCollectDependenciesTask.TASK_NAME)
rootProjectFeatureUsageReportTask.dependsOn(collectTask)
}
}
Zak Taccardi
08/08/2023, 9:19 PMZak Taccardi
08/08/2023, 9:23 PMZak Taccardi
08/08/2023, 9:32 PMWhat you really should never be doing is looping over subprojects from the root project. Convention plugins allow you to avoid thisactually, I don’t know if it’s worse to access the root project from a subproject, or if it’s worse to access the subproject from the root project
Zak Taccardi
08/08/2023, 9:33 PMsubprojects { }
- not allprojects { }
- allprojects
will loop over the root project, which you do not need, bc it is doing the aggregationZak Taccardi
08/08/2023, 9:34 PMplugins.withId(..) { }
to wait until the relevant plugins are applied to wait until your subproject producer tasks are registeredZak Taccardi
08/08/2023, 9:35 PMafterEvaluate { }
but that invites other issues around timing depending on what exactly you’re doingSam Edwards
08/08/2023, 9:46 PMIf you're going to do it the wrong way, the subprojects should add their dependency to the root project task when the subprojects are configuredI've tried this and it didn't work... But so many caches and things, maybe just have to try again.
Zak Taccardi
08/08/2023, 9:50 PMZak Taccardi
08/08/2023, 9:56 PMtask.outputs
and filter on it as appropriateVampire
08/09/2023, 6:59 AMmaybe just have to try again.
Please do not. You were already told the proper and safe way to share things cross-project. You can also have a look at the Jacoco Report Aggregation plugin or the rest report Aggregation plugin. Both use the proper way and by using a lenient artifact view support that not all projects are producers, so exactly what you want.