what provider gives me a `Provider<File>`? s...
# community-support
c
what provider gives me a
Provider<File>
? since this isn't valid
Copy code
project.layout.file("diagrams/class.puml")
v
You give a relative path, to what should that relative path be relative?
I guess what you intended was
Copy code
project.layout.projectDirectory.file("diagrams/class.puml")
c
yeah, that would work... not certain why files should be different from file 😉
v
why files should be different from file
I don't get what you mean by that
c
the api for
files
takes
Any...
and can be coerced to a single which also just worked in my use case (and is shorter) 😕
v
It takes
Any
for historical reasons (pre-Kotlin DSL and pre-Providers) And iirc it documents that relative paths given to it are used relative to the project directory.
c
sure, point being is I can pass stringy paths and it did what I mean 😉
I would expect layout.file and layout.files to have a similar api
anyways, you told me what I wanted, was filing a bug
v
Ah,
layout.files
, I see. Yeah, it is defined in terms of
Project#files
and if a
FileCollection
is ok as result to work with further on probably is also ok, just a bit less explicit. 🙂
Btw. to answer your initial question, for example
Copy code
project.layout.file(providers.provider { File(...) })
But the
...
must not be a relative path or the build is inherently broken as it would depend on current working directory of the daemon which often is the project directory, but also often is not and it is not guaranteed what it is.
c
https://gitlab.com/Plunts/plantuml-gradle-plugin/-/issues/29#note_2403973823 in the event you should feel like elaborating on the wise of all of this to this guy... I feel like I'm terrible at explaining this stuff I especially don't understand all the virtues of the layout
I'm going to speculize he hasn't gone quite as far as I intended. I probably need to run some code to show the point more...
v
c
Yeah, I didn't really look at the code but I was also talking about more than just those two calls. I was trying to incentivize the change to the entire system. However, I figured you might also explain why project.layout.projectdirectory is better than using file(). That's something I can't explain. I'm thinking that methods like writeTo for a signature are good but they should be backed by the property so that they don't evaluate until the task is evaluated. I'll see if I can't give him an example later, My publishing example is great 😉, But I might write a simple task that should demonstrate the difference between it being evaluated and not being evaluated until the task runs. Unless you happened to know some code that's easy to copy paste there
v
Well, as I described, if you for example have the file generated by another task, properly using `Property`s would preserve the task dependency while not doing so will loose the dependency even if there would be a
Provider
overload of the method. Having the function like that would mean you need to support all the possible variants like
File
,
RegularFile
,
Provider<RegularFile>
,
Provider<File>
, and any other possibility existing now or being added in the future. If it would be a
RegularFileProperty
, you could simply use everything the Gradle version you are using in the consumer project supports.
layout.projectDirectory
vs.
file()
per-se is not so much different, more depending on what the thing you try to configure expects / supports. The
layout
is mainly more explicit that you resolve a relative path relative to the project directory, but
file()
does the same and also documents that. When it comes to
layout.buildDirectory
or a
Provider<RegularFile>
things are different, because the project directory cannot change, the output path of a task property or the build directory can change.
c
I thought there was also something to do with relative versus absolute file path and build caching that went along with the layout object
Anyways I got to get up get dressed and head to work. Continue later
Either way, thanks for commenting on that issue
👌 1
v
I think relative and absolute paths would behave the same with both methods. How build cache is affected depends on the configured path sensitivity on the according task file input property.
👍 1