This message was deleted.
# community-support
s
This message was deleted.
n
Copy code
project.getLayout().dir(regularFileProperty.getAsFile().map(File::getParentFile))
e
That gives a
Provider<Directory>
but I need a
DirectoryProperty
n
oh right, sorry. wrap it with a directoryProperty like so:
Copy code
project.getObjects().directoryProperty().value(Provider<Directory>)
there might be a simpler way though 🤔 this is rather verbose
e
It also causes issues with the configuration cache. I don't have the exact error in front of me, but it is related to calling
map
before the task runs. Although that may be the fault of the API I'm calling.
n
Perhaps you should avoid the
getAsFile
and use a mapper there as well, that way the entire chain should be safe to use, I think.
v
Also the consumer expecting
DirectoryProperty
is probably badly designed or could even be called buggy. It should accept instead a
Provider<Directory>
, then it would also accept
DirectoryProvider
and
DirectoryProperty
.
c
that shouldn’t be necessary.
DirectoryProperty.set
is overloaded with variants taking
Directory
and
Provider<Directory>
e
Also the consumer expecting
DirectoryProperty
is probably badly designed or could even be called buggy. It should accept instead a
Provider<Directory>
, then it would also accept
DirectoryProvider
and
DirectoryProperty
.
The reasoning I got from them is:
Copy code
the problem of Provider<Directory> is that we cannot set the location ourselves which we want to do in order to avoid accidental overrides with 2 tasks outputing in the same location. That's why we use DirectoryProperty.
Perhaps you should avoid the
getAsFile
and use a mapper there as well
Here's what I ended up with:
Copy code
objects.directoryProperty().run {
  fileProvider(
    task.output.map { outputFile ->
      outputFile.asFile.parentFile
    }
  )
}
How can I avoid calling
asFile
here?