Set a gradle.properties property from a convention plugin

Using Gradle 8.14, I want to add Dokka to my convention plugin (so that all projects which apply my plugin automatically have Dokka), but I want to use the new Dokka v2. The way Dokka did it is that both v1 and v2 live in the same artifact (i.e. you apply the same plugin regardless of which version you want to use) and you control which version you want by adding a property to gradle.properties:

org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled

More details here.

I don’t want each project to have to add this property, but I don’t see a way of doing it in a convention plugin. Is it possible? Thanks!

I’m definitely not saying you should, but you could use tight coupling.

If you look at the sources, you can find that they check the Gradle property, but if it is not set, also check the extra properties. Even the sources clearly state that this is only intended for their tests as you cannot set Gradle properties from inside Gradle and that it might break any time.

But the whole feature is experimental anyway, so you might be on with that. So you plugin could set the property as extra property and as long as the consumer does not set a different value as Gradle property, it will be used currently.

Another option would be to have some code that checks the value the consumer has set (or not) and fail the build, telling then to set the property in their Gradle properties.