Hi, we are removing builddir from our build.gradle...
# community-support
a
Hi, we are removing builddir from our build.gradle file, I am wondering what is the difference between layout.buildDirectory.asFile.get() and layout.buildDirectory.get().asFile? Previous, we used a lot of
${buildDir}
to get the string for output, is there any more idiomatic way to write it with new build.directory api?
k
The two are identical. Feel free to use either. If you're chaining resolved directories within the build directory, the
buildDirectory.dir(...)
or
.file(...)
methods will let you get providers to ensure they behave with lazy evaluation. (You'd still eventually use
.get().asFile
or the other flipped version)
v
Kevin is absolutely right about this two being identically, and identically bad. Like with any provider, if you call
.get()
at configuration time you introduce ordering problems, timing problems, and race conditions. It could always happen that the value changes after you got it and thus you used a stale value. So whenever possible try to not
get
the provider at configuration time but work with providers.
👆 3