I have a plugin where it configures an extension on each task:
compileTasks.configureEach { task ->
val warningsOptions = task.extensions.create("warnings",
WarningsOptionsExtension::class.java,
project.objects)
warningsOptions.warningDump.set(project.layout.buildDirectory.file("${task.name}.stderr"))
// ...
}
Another task, warningsReport
, has all of these warning dumps as its inputs.
When I run the integration tests, the tests fail with:
* What went wrong:
Could not determine the dependencies of task ':warningsReport'.
> Extension 'warnings' property 'warningDump' is declared as an output property of extension 'warnings' (type WarningsOptionsExtension) but does not have a task associated with it.
Clearly I added the extension via task.extensions
, so as far as I know, it’s owned by the task.
I tried to figure out how JacocoTaskExtension
was doing the same thing, but I see it doing more or less the same thing.
So what is missing here?
Full source for the plugin class:
class WarningsPlugin: Plugin<Project> {
override fun apply(project: Project) {
project.pluginManager.apply(ReportingBasePlugin::class.java)
val compileTasks = project.tasks.withType(JavaCompile::class.java)
val warningDumps = mutableListOf<Provider<RegularFile>>()
compileTasks.configureEach { task ->
val warningsOptions = task.extensions.create("warnings",
WarningsOptionsExtension::class.java,
project.objects)
warningsOptions.warningDump.set(project.layout.buildDirectory.file("${task.name}.stderr"))
warningDumps.add(warningsOptions.warningDump)
// Adding the extension doesn't add the extension as a @Nested,
// so it seems we have to add the output ourselves?
// But if I do this, I get an error about it already being declared as an output for the extension!
// task.outputs.file(warningsOptions.warningDump)
val listener = FileWritingStandardOutputListener(warningsOptions.warningDump)
task.logging.addStandardErrorListener(listener)
task.doLast { listener.close() }
}
project.tasks.register("warningsReport", WarningsReport::class.java) { task ->
task.dependsOn(compileTasks)
task.warningDumps.setFrom(warningDumps)
val reportingExtension = project.extensions.getByName(ReportingExtension.NAME) as ReportingExtension
task.reports.html.outputLocation.set(reportingExtension.baseDirectory.dir("warnings"))
task.reports.html.required.set(true)
}
}
}