Skip to content

Use the GRADLE_PLUGIN_API_VERSION_ATTRIBUTE to set the required minim…#498

Merged
JakeWharton merged 1 commit intocashapp:trunkfrom
hfhbd:gradle-attribute
Oct 8, 2025
Merged

Use the GRADLE_PLUGIN_API_VERSION_ATTRIBUTE to set the required minim…#498
JakeWharton merged 1 commit intocashapp:trunkfrom
hfhbd:gradle-attribute

Conversation

@hfhbd
Copy link
Copy Markdown
Contributor

@hfhbd hfhbd commented Oct 8, 2025

…um version of Gradle.

It available since 7.0, but Gradle 8.7 improved the error message: gradle/gradle#24609


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

…um version of Gradle.

It available since 7.0, but Gradle 8.7 improved the error message: gradle/gradle#24609
@JakeWharton JakeWharton enabled auto-merge (squash) October 8, 2025 14:31
@JakeWharton JakeWharton merged commit 2635c83 into cashapp:trunk Oct 8, 2025
2 checks passed
@hfhbd hfhbd deleted the gradle-attribute branch October 8, 2025 14:42
@DennisTsar
Copy link
Copy Markdown

Just FYI this doesn't actually validate/show the message when using an unsupported Gradle version as Gradle selects the runtimeElements variant, not apiElements where the attribute is set .

@hfhbd
Copy link
Copy Markdown
Contributor Author

hfhbd commented Dec 24, 2025

Gradle consumes both resolvable configurations and validates both of them. Let me add a test.

We also use api to fail compilation of consumers of the licensee plugin as a regular library (when creating a new plugin on top of it).

@DennisTsar
Copy link
Copy Markdown

I can use Licensee 1.14.1 with Gradle 8.9 and get no errors, even though it declares a minimum version of 8.12.

@hfhbd
Copy link
Copy Markdown
Contributor Author

hfhbd commented Jan 5, 2026

@DennisTsar Sorry, you are right: https://docs.gradle.org/current/userguide/java_library_plugin.html#consumable_configurations The apiElements only contains the api dependencies. I noticed the bug/the behavior in a more complex Gradle plugin that also uses api elements, so it did work with apiElements but the right way is to use runtimeElements because it contains api AND implementation dependencies, so Gradle will always consume the runtimeElements when running a Gradle plugin.

I added a test and also fixed it: #542

@DennisTsar
Copy link
Copy Markdown

I'm not sure if it's a Gradle bug, but even setting the attribute on both apiElements and runtimeElements isn't enough to get the nicer error message from gradle/gradle#24609. In Gradle's tests, they set it on all consumable configurations, which does show the improved error.

@hfhbd
Copy link
Copy Markdown
Contributor Author

hfhbd commented Jan 6, 2026

I do get the correct (and minified) error message using runtimeElements only: https://github.com/hfhbd/licensee/blob/1497de3b25d739fc4868d9b8be4efae8a572f15d/src/test/kotlin/app/cash/licensee/LicenseePluginFixtureTest.kt#L272

I only added apiElements (back) to also add plugin authors support.

A java library only has 4 variants by default: apiElements, runtimeElements, sources and javadoc. The latter two do not require the gradle version attributes.

@DennisTsar
Copy link
Copy Markdown

I believe that's the old error message? The new one is

Plugin ... requires at least Gradle 9.0. This build uses Gradle 8.9.

@hfhbd
Copy link
Copy Markdown
Contributor Author

hfhbd commented Jan 6, 2026

Yeah, true... IMHO this is a bug at Gradle, there is no need to validate the sources or javadoc variants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants