This message was deleted.
# community-support
s
This message was deleted.
v
https://docs.gradle.org/current/userguide/incremental_build.html#sec:task_input_output_validation:
[...]
it does the following for each property before the task executes:
[...]
•
@OutputDirectory
- verifies that the path doesn’t match a file and also creates the directory if it doesn’t already exist.
I don't know why
@Optional
should have any influence.
@Optional
on an input file or directory property does not mean you can configure a non-existing path. It means that you are allowed to not configure it, but if you configure it, it must exist (when an input)
k
I had an
@OutputDirectory
annotated with
@Optional
, and set it, expecting the directory to exist, only to encounter an error stating that it didn't.
v
I just tried with this complete build script:
Copy code
abstract class Foo : DefaultTask() {
    @get:Optional
    @get:OutputDirectory
    abstract val out: DirectoryProperty

    @TaskAction
    fun foo() = Unit
}

val foo by tasks.registering(Foo::class) {
    out = layout.buildDirectory.dir("foo")
}
When I executed the
foo
task, the directory was created as expected.
k
I wonder if there are any complications relating to
@Nested
output properties, then? On paper, it shouldn't, but, barring external factors, I don't see why an
@OutputDirectory
property would fail to create the directory. (Maybe nested directories? Hard to say.)
v
🤷‍♂️
k
Worst case, it's probably something that can be worked around.
v
Also this works fine:
Copy code
interface Bar {
    @get:OutputDirectory
    val out: DirectoryProperty
}

abstract class Foo : DefaultTask() {
    @get:Nested
    abstract val bar: Bar

    @TaskAction
    fun foo() = Unit
}

val foo by tasks.registering(Foo::class) {
    bar.out = layout.buildDirectory.dir("foo")
}
So maybe you can show some MCVE?