“<https://docs.gradle.org/8.7-rc-1/release-notes.h...
# plugin-development
e
When applying a plugin that requires a higher version of Gradle…” How does a plugin “require” a higher version of Gradle? 🤔
v
I guess if you only publish feature variants with the Gradle version attribute set.
e
I guess that makes sense. Now how do I do that for only the version that I am interested in?
v
Do what? For which version?
e
Say I want to force all my users to upgrade to 8.5+, I don’t want to support any lower versions of Gradle (_do what_: require a version and above, _for which version_: an arbitrary minimum version for which I want to force users to upgrade to)
v
Still not fully getting what you mean. Just set the attribute to 8.5 and you get that.
Or do you mean how to set it for the only available feature variant?
e
Just set the attribute to 8.5 and you get that.
Ah yeah I get it now. Didn’t know we could set that ourselves
v
You have to, otherwise it is not set at all
On requesting it is set to the version of running Gradle
👍🏾 1
On publishing you can use it to require a minimum Gradle version, or to have multiple variants of the plugin for different Gradle versions by setting that attribute accordingly and changing the capability of the additional variants to be the same as the main variant, so that the only difference is that attribute.
Or maybe also the Java compatibility attribute if you also want different variants for different Java version executing Gradle
e
Ah nice, that way Gradle can select the right “variant” of the plugin to use. Thanks, I think I really get it now 😄
v
Exactly
You can always check with the
outgoingVariants
task which variants are going to be published and whether they are like needed.
👌🏾 1
So to be more concrete, for the sole variant of a plugin:
Copy code
configurations.apiElements {
    attributes {
        attribute(GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named("8.5"))
    }
}
configurations.runtimeElements {
    attributes {
        attribute(GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, objects.named("8.5"))
    }
}
e
Why apiElements & runtimeElements ? (or better put, how would I have figured out what configurations to put this on? My initial guess:
outgoingVariants
? 🤔)
☝️ 1
For the multi-capability one, the one where the plugin supports multiple versions of Gradle, I would be able to do that using the “java features plugin” (I dont remember whats its called exactly, jus that it exists) right?
v
That's not a plugin, I think you confuse it with the Java fixtures plugin
Or rather, it is not a separate plugin, is part of the
java
plugin
You just define feature variants and on the variants set the capability to the same as the one on the main variant and the Gradle version attribute to the respective value
👍🏾 1
e
Ah okay. I will do some more research here
or better put, how would I have figured out what configurations to put this on?
You could also use
configurations.matching { it.isCanBeConsumed } .configureEach { ... }
but imho that is too big a hammer, as it also sets it then on javadoc, sources, and so on and there is not really a reason to set the attribute on those
👍🏾 1