Using getProject() in task types

According to the documentation, it says that when I am drafting a custom task type, I should avoid using getProject() in contexts where a task would be running.

I am wondering about things like using the project object in things like an onlyIf() block or a provider that you pass in. A common thing I see is the passing of project.version as a provider, and I am wondering if something like

abstract val version: Property<String>

init {
    version.convention(providers.provider {
        project.version.toString()
    })
}

would constitute “using getProject() incorrectly”.

onlyIf { ... } is executed at execution time, so yes, using Task#getProject there is not compatible to configuration cache.

Using it within a provider like you showed should not be a problem, because providers are calculated at the time the configuration cache is persisted.