Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider using different Gradle attributes for dokkatooHtmlPublicationPluginClasspathApiOnlyConsumable #165

Open
martinbonnin opened this issue Feb 12, 2024 · 9 comments
Labels
blocked-by:Gradle Blocked by a bug/missing feature in Gradle bug Something isn't working

Comments

@martinbonnin
Copy link
Contributor

martinbonnin commented Feb 12, 2024

After upgrating to 2.1.0, we started having KSP errors because the KSP classpath would select the dokkatooHtmlPublicationPluginClasspathApiOnlyConsumable variant of some projects instead of the jvmRuntimeElements ones. They are indeed quite similar:

--------------------------------------------------
Variant dokkatooHtmlPublicationPluginClasspathApiOnlyConsumable
--------------------------------------------------
Shared Dokka Plugins for consumers that will assemble a html Publication using the Dokka Module that this project produces

Capabilities
    - com.apollographql.apollo3:apollo-ast:4.0.0-beta.5-SNAPSHOT (default capability)
Attributes
    - dev.adamko.dokkatoo.classpath  = dokka-publication-plugins
    - dev.adamko.dokkatoo.format     = html
    - org.gradle.category            = library
    - org.gradle.dependency.bundling = external
    - org.gradle.jvm.environment     = standard-jvm
    - org.gradle.libraryelements     = jar
    - org.gradle.usage               = java-runtime

vs

--------------------------------------------------
Variant jvmRuntimeElements
--------------------------------------------------
Elements of runtime for main.

Capabilities
    - com.apollographql.apollo3:apollo-ast:4.0.0-beta.5-SNAPSHOT (default capability)
Attributes
    - org.gradle.category                = library
    - org.gradle.jvm.environment         = standard-jvm
    - org.gradle.libraryelements         = jar
    - org.gradle.usage                   = java-runtime
    - org.jetbrains.kotlin.platform.type = jvm
Artifacts
    - build/libs/apollo-ast-jvm-4.0.0-beta.5-SNAPSHOT.jar (artifactType = jar)

I was able to workaround by forcing "unselection" of the dokkatoo variant:

  configurations.configureEach {
    if (name.lowercase().contains("dokkatooHtmlPublicationPluginClasspathApiOnlyConsumable".lowercase())) {
      attributes {
        attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, "poison"))
      }
    }
  }

TBH I'm not 100% what the root cause is but would it be possible to use more specific attributes for dokkatooHtmlPublicationPluginClasspathApiOnlyConsumable? Maybe org.gradle.usage = dokkatoo-plugin?

@aSemy aSemy added the bug Something isn't working label Feb 12, 2024
@aSemy
Copy link
Contributor

aSemy commented Feb 12, 2024

Thanks for the report!

The configurations have different attributes so it's a mystery why Gradle is confusing them.

I've tried various combinations of setting org.gradle.usage but nothing seems to work. It needs to be set to 'java-runtime', otherwise Gradle won't fetch the dependency from Maven Central.

Possibly it's an issue with KSP, which doesn't seem to add any attributes to its Configurations.

It looks like this is another bug/flaw/undocumented feature in Gradle so I've raised an issue gradle/gradle#28053. I'm not sure how best to workaround it.

@aSemy aSemy added the blocked-by:Gradle Blocked by a bug/missing feature in Gradle label Feb 12, 2024
@martinbonnin
Copy link
Contributor Author

Smaller reproducer with included builds instead of KSP here: https://github.com/martinbonnin/reproducer-attributes

tldr; not really sure what's happening down there but given all the existing ecosystem around this, I'd feel more comfortable if the dokkattoo artifacts were using a dedicated org.gradle.usage attribute. Maybe there need to be an "intermediate" configuration? One that resolves from Maven Central using java-runtime but then exposes something else in outgoingVariants?

@aSemy
Copy link
Contributor

aSemy commented Feb 18, 2024

This issue seems relevant gradle/gradle#26463

@aSemy
Copy link
Contributor

aSemy commented Mar 17, 2024

#173 seems to have helped in some cases, but not all

apollographql/apollo-kotlin@a58454c

@martinbonnin
Copy link
Contributor Author

Right. It's working when everything is in the same build but failing to compile build scripts in composite builds. From that commit ./gradlew -p tests build fails IIRC

@aSemy
Copy link
Contributor

aSemy commented May 4, 2024

hey @martinbonnin, when you try K2 could you also try and remove the 'poison' workaround? I'm curious whether it would help. See #170 (comment)

@martinbonnin
Copy link
Contributor Author

martinbonnin commented May 4, 2024

Not working for us sadly (commit good commit (see below)):

$ ./gradlew -p tests build

> Configure project :compiler-plugins-app
w: file:///Users/mbonnin/git/apollo-kotlin/tests/compiler-plugins/app/build.gradle.kts:1:1: @OptIn without any arguments has no effect
e: file:///Users/mbonnin/git/apollo-kotlin/tests/compiler-plugins/app/build.gradle.kts:1:13: Unresolved reference: ApolloExperimental
e: file:///Users/mbonnin/git/apollo-kotlin/tests/compiler-plugins/app/build.gradle.kts:1:13: An annotation argument must be a compile-time constant
e: file:///Users/mbonnin/git/apollo-kotlin/tests/compiler-plugins/app/build.gradle.kts:3:34: Unresolved reference: annotations

This somewhat fails when resolving included build. Note that this commit is using KGP RC2 but languageVersion 1.9 because we're stuck on other issues to enable languageVersion 2.0 (but I'd say the important thing is the KGP version here?)

@aSemy
Copy link
Contributor

aSemy commented May 5, 2024

Thanks for trying! Did you also check with the latest Dokkatoo version? The commit you linked shows v2.2.0, but the latest is v2.3.1. This contains a fix relevant for composite builds - gradle/gradle#28695

@martinbonnin
Copy link
Contributor Author

Wooops, apologies I didn't realize there was an old branch named update-dokkatoo and my push didn't go through.

This is the good commit I tried yesterday. It still fails with 2.3.1 sadly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked-by:Gradle Blocked by a bug/missing feature in Gradle bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants