Skip to content

Conversation

@adam-enko
Copy link
Member

@adam-enko adam-enko commented Nov 4, 2025

Continuation of #4286

Fixes KT-72019 and adamko-dev/dokkatoo#165

Credit goes to @martinbonnin!

Summary

Unfortunately, Gradle's matching algorithm prioritises the number of attributes matched over the actual attribute values. (Note that if a candidate does not have a requested attribute this still counts as a match!) This behaviour makes it impossible to strictly match Configurations, and leads to situations like this where two 'ecosystems' step on each other's toes.

The solution is in two parts:

  1. Reduce the number of attributes DGP uses.

    This prevents the matching algorithm from over-matching based on attributes alone. The Bundling attribute is removed, since this is not important for DGP classpaths.

  2. (As suggested by @martinbonnin) DGP configurations use a custom value for the Usage attribute, and use a one-way AttributeCompatibilityRule so DGP can still resolve dependencies.
    (A one-way rule should minimise ugly issues where rules can leak.)

See the KDoc of DokkaJavaRuntimeUsageCompatibilityRule for details.

@adam-enko adam-enko force-pushed the martinbonnin/compatibility branch from f428119 to 3b56830 Compare November 4, 2025 09:01
- Remove 'Bundling' from the 'Dokka JARs' attributes.
  Dokka doesn't need to express an opinion on how the dependencies are distributed.
  Fewer attributes means Gradle is less likely to get confused about the attributes.
- Remove modification of other configurations. It's risky, as other configurations might lazily add attributes. And with the removal of 'Bundling' it shouldn't be necessary.
- Refactoring to put things in better places.
- Update the tests.
- Register DokkaJavaRuntimeUsageCompatibilityRule in DokkaBasePlugin, so it's next to the other usage of `attributesSchema {}`, and it's always needed.
@martinbonnin
Copy link
Contributor

Wowowowow! That's a lot of tests 👀
I'm not super familiar with the test suite but let me know if I can help with anything.

@Vampire
Copy link

Vampire commented Nov 4, 2025

Just in case you missed it on the copied PR.

Before considering this PR, I'd like to suggest reviewing my analysis of the problem just posted to adamko-dev/dokkatoo#165 (comment) :-)

Because I think the proper solution is not to do what is suggested here.

@adam-enko adam-enko added the runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin label Nov 4, 2025
@adam-enko adam-enko added this to the Dokka 2.1.x milestone Nov 4, 2025
@adam-enko
Copy link
Member Author

I'm not super familiar with the test suite but let me know if I can help with anything.

I think we're good! There was a flaky test but it should be fixed now #4335

@adam-enko
Copy link
Member Author

Just in case you missed it on the copied PR.

Before considering this PR, I'd like to suggest reviewing my analysis of the problem just posted to adamko-dev/dokkatoo#165 (comment) :-)

Because I think the proper solution is not to do what is suggested here.

Thanks for the link. Unfortunately, it wouldn't help.

It's not possible to modify the attributes of KGP Configurations. Additionally, any fix needs to work with older KGP versions (such as those bundled into older Gradle versions). Also, itt's not appropriate for DGP to use the KotlinPlatformType, which is only relevant for KMP. Adding it won't help with non-KMP consumers.

@adam-enko adam-enko marked this pull request as ready for review November 5, 2025 06:53
Copy link
Collaborator

@whyoleg whyoleg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in the PR are a bit out of my league, so you could safely ignore my review, and approval from the KBT side will be enough :)

In any case, thanks for the long description of what DokkaJavaRuntimeUsageCompatibilityRule is!

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

Labels

runner: Gradle plugin An issue/PR related to Dokka's Gradle plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants