This message was deleted.
# plugin-development
s
This message was deleted.
๐Ÿงต 1
v
Please do not split topics across several threads. This makes following the conversation in the threads view very hard as the context of the other messages is missing. If you have additional information either edit the original message or post to its thread. Regarding the problem, the directory not having any files in them is different from the directory not being present. No matter whether you use optional or skip when empty, if you actually configure a directory, Gradle expects the directory to be valid and present.
You need to add some logic like making that an
@Internal
property and having another property with those annotations derived from that property and then in a
map
checking whehter the directory exists and mapping to
null
if it does not exist. Something like that.
There should be examples in this Slack already regarding that.
a
thank you for the fast answer! I didnt have any other threads that I was messaging in , so i may be confused with someone else ๐Ÿ˜… so not a solution would be turning it into:
Copy code
@get:InputFile
@get:SkipWhenEmpty
@get:Optional
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val buildDir: RegularFileProperty
and :
Copy code
if (project.buildDir.exists()) {
                buildDir.set(project.buildDir)
            }
v
I didnt have any other threads that I was messaging in , so i may be confused with someone else
No, you have two threads. The second only contains "adding
@Optional
doesnt work either. it produces same error message".
so not a solution would be turning it into:
No, with
RegularFileProperty
you would have the same problem
a
alrighty I understand. keep it in one message (makes sense). and I believe I understand your response so ill try it out. thanks
๐Ÿ‘Œ 1
for anyone who follows along:
Copy code
if (project.buildDir.exists()) {
    buildDir.set(project.buildDir)
} else {
    buildDir.set(Providers.notDefined())
}
and make it
@Optional
i then check in the task to see if its present
v
Not the best idea,
Providers
is an internal class
Copy code
buildDir.set(layout.buildDirectory.flatMap { provider { if (it.asFile.exists()) it else null } })
if you really want to unset it if the directory does not exist. if there is a convention defined for the property it will then also not be used.
a
Ah ok! I figured it was off with internal packaging name