# How do I declare an output on an extension which is added to a task?

**URL:** <https://discuss.gradle.org/t/how-do-i-declare-an-output-on-an-extension-which-is-added-to-a-task/41433>\
**Category:** Help/Discuss\
**Tags:** plugins\
**Created:** [November 11, 2021, 11:15pm UTC](https://discuss.gradle.org/t/how-do-i-declare-an-output-on-an-extension-which-is-added-to-a-task/41433 "2021-11-11T23:15:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![trejkaz](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/trejkaz/32/3338_2.png) [@trejkaz](https://discuss.gradle.org/u/trejkaz)\
**Post date:** [November 11, 2021, 11:15pm UTC](https://discuss.gradle.org/t/how-do-i-declare-an-output-on-an-extension-which-is-added-to-a-task/41433/1 "2021-11-11T23:15:23Z")

</div>

I have a plugin where it configures an extension on each task:

```gradle
        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:

```gradle
* 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:

```gradle
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)
        }
    }
}

```
