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

Resolving MPP dependencies - Could not resolve all files for configuration ':protomodule:compileProtoPath' - Cannot choose between the following variants #391

Closed
olamelin opened this issue Feb 28, 2020 · 7 comments · Fixed by #489
Assignees
Labels

Comments

@olamelin
Copy link

olamelin commented Feb 28, 2020

Given a simple multi module project as can be seen here https://github.com/olamelin/protobuf-gradle-plugin-issue the protomodule:extractIncludeProto fails with the following stack trace

Execution failed for task ':protomodule:extractIncludeProto'.
> Could not resolve all files for configuration ':protomodule:compileProtoPath'.
   > Could not resolve com.squareup.okio:okio:2.4.3.
     Required by:
         project :protomodule > project :okhttp > com.squareup.okhttp3:okhttp:4.4.0
      > Cannot choose between the following variants of com.squareup.okio:okio:2.4.3:
          - jvm-api
          - jvm-runtime
          - metadata-api
        All of them match the consumer attributes:
          - Variant 'jvm-api' capability com.squareup.okio:okio:2.4.3:
              - Unmatched attributes:
                  - Found org.gradle.status 'release' but wasn't required.
                  - Found org.gradle.usage 'java-api' but wasn't required.
                  - Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
              - Compatible attribute:
                  - Required org.gradle.libraryelements 'resources' and found compatible value 'jar'.
          - Variant 'jvm-runtime' capability com.squareup.okio:okio:2.4.3:
              - Unmatched attributes:
                  - Found org.gradle.status 'release' but wasn't required.
                  - Found org.gradle.usage 'java-runtime' but wasn't required.
                  - Found org.jetbrains.kotlin.platform.type 'jvm' but wasn't required.
              - Compatible attribute:
                  - Required org.gradle.libraryelements 'resources' and found compatible value 'jar'.
          - Variant 'metadata-api' capability com.squareup.okio:okio:2.4.3:
              - Unmatched attributes:
                  - Required org.gradle.libraryelements 'resources' but no value provided.
                  - Found org.gradle.status 'release' but wasn't required.
                  - Found org.gradle.usage 'kotlin-api' but wasn't required.
                  - Found org.jetbrains.kotlin.platform.type 'common' but wasn't required.

The issue happens when there is a dependency on a Kotlin MPP project as the com.squareup.okio:okio:2.4.3 is.
It looks to be the same that existed in Kapt but has been resolved in version 1.3.60 https://youtrack.jetbrains.com/issue/KT-31641

@voidzcy
Copy link
Collaborator

voidzcy commented Feb 28, 2020

Related to change made in #366. https://youtrack.jetbrains.com/issue/KT-31641#focus=streamItem-27-3698024.0-0 sounds to be likely the cause of this issue.

The problem is a total absence of attributes on the resolved configuration coupled with the default disambiguation rules from the Kotlin plugins.
Kotlin plugins define their own org.gradle.usage disambiguation rule which picks java-runtime-jars when nothing is requested.
Unfortunately, there is another Kotlin added attribute, org.jetbrains.kotlin.platform.type, which also has a disambiguation rule. But that one prefers common when no value is requested.
This means that between java-runtime and common as disambiguated values, there is no matching variant.

@olamelin
Copy link
Author

olamelin commented Mar 4, 2020

But based on ljacomet's comment here gradle/gradle#6389 (comment) is this not the same consumer issue that the kapt suffered from as well as the ben-manes/gradle-versions-plugin#334 issue?

@iainmcgin
Copy link

iainmcgin commented Apr 6, 2020

I was able to work around this issue by adding the following to my build.gradle.kts:

configurations.forEach {
    if (it.name.toLowerCase().contains("proto")) {
        it.attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage::class.java, "java-runtime"))
    }
}

This is adapted from this suggestion that was more specific to using Square's wire implementation of gRPC, but in searching around for solutions to this issue I'm seeing a lot of related variant selection ambiguity issues. Hopefully the snippet above will help figure out how to update this plugin.

@olamelin
Copy link
Author

olamelin commented Apr 7, 2020

It worked like a charm

cpiotr added a commit to cpiotr/filmbag that referenced this issue May 26, 2020
There was a build problem with dependencies. OkHttp uses okio and there
were additional attributes missing.
More details: google/protobuf-gradle-plugin#391
@gnarea
Copy link

gnarea commented Jul 14, 2020

FYI, someone from the Gradle team had a quick look at this issue in this plugin and here's his summary: gradle/gradle#12126 (comment)

@alastairpatrick
Copy link

I worked around this by depending on the older 0.8.10 version of protobuf-gradle-plugin.

0.8.14 error
0.8.13 error
0.8.12 error
0.8.11 error
0.8.10 works
0.8.9 works

@voidzcy
Copy link
Collaborator

voidzcy commented Nov 19, 2020

From gradle/gradle#12126 (comment), the compileProtoPath configuration indeed has some problem.

the protobuf plugin doesn't set the right attributes on the compileProtoPath configuration to be able to resolve the right variant.

Now as for setting the attributes: an error you make is that the attributes must be set on the resolvable configurations. It doesn't make sense to set attributes on compileOnly or implementation because those are just used to declare dependencies. They are never resolved. When we talk about the "consumer", this is actually a dependency graph, resolved. So compileClasspath, runtimeClasspath, compileProtoPath, ...

The easiest fix is probably to let it inherit from compileClasspath instead of implementation + compileOnly (Update: this will not work, as attributes are not inherited). Another way is to directly extract included protos from compileClasspath with an ArtifactView that request resources, and we get rid of compileProtoPath.

@voidzcy voidzcy added the bug label Nov 19, 2020
@voidzcy voidzcy self-assigned this Dec 8, 2020
@voidzcy voidzcy added this to the Next milestone Feb 2, 2021
ikhoon added a commit to ikhoon/armeria that referenced this issue Aug 11, 2021
- Dropwizard 3.0.23 -> 2.0.24
- Dropwizard Metrics 4.2.2 -> 4.2.3
- Jackson 2.12.3 -> 2.12.4
- Jetty 9.4.42 -> 9.4.23
- GraphQL-Java 16.2 -> 17.1
- gRPC-Java 1.38.1 -> 1.39.0
  - protobuf-java 3.12.0 -> 3.17.2
  - protobuf-gradle-plugin 0.8.13 -> 0.8.17
- Kotlin 1.5.10 -> 1.5.21
  - kotlinx-coroutines-core 1.5.0 -> 1.5.1
- Logback 1.2.3 -> 1.2.5
- Micrometer 1.7.1 -> 1.7.2
- Netty 4.1.65 -> 4.1.66
  - tcnative-boringssl-static 2.0.39 -> 2.0.40
  - transport-native-io_uring 0.0.5 -> 0.0.8
- java-jwt 3.16.0 -> 3.18.1
- Reactor 3.4.7 -> 3.4.9
- RESTeasy 4.6.1 -> 4.7.1
- RxJava 3.0.13 -> 3.1.0
- scala-collection-compat 2.4.4 -> 2.5.0
- ScalaPB 0.11.4 -> 0.11.5
- ScalaPB json4s 0.11.1 -> 0.12.0
- SLF4J 1.7.31 -> 1.7.32
- Spring 5.3.8 -> 5.3.9
- Spring Boot 2.5.2 -> 2.5.3
- ZooKeeper 3.6.2 -> 3.6.3
- Build
  - Checkstyle 8.43 -> 8.45.1
  - Error Prone 2.7.1 -> 2.8.1
  - Eureka 1.10.15 -> 1.10.16
  - graphql-dgs-client4.3.1 -> 4.5.0
  - groovy-xml 3.0.5 -> 3.0.8
  - jmh 1.32 -> 1.33
  - jsoup 1.13.1 -> 1.14.1
  - MUnit 0.7.26 -> 0.7.28
  - Proguard 7.1.0 -> 7.1.1
  - Reactor gRPC 1.0.1 -> 1.1.0
  - reactor-kotlin-extensions 1.1.3 -> 1.1.4
- Shaded
  - copmletable-futures 0.3.4 -> 0.3.5
- Miscellaneous
  - Add Brotli's license
  - Add a workaround for a configuration error of gradle-proto-plugin
    - google/protobuf-gradle-plugin#391
ikhoon added a commit to line/armeria that referenced this issue Aug 20, 2021
- Curator 5.1.0 -> 5.2.0
- Dropwizard 2.0.23 -> 2.0.24
- Dropwizard Metrics 4.2.2 -> 4.2.3
- Jackson 2.12.3 -> 2.12.4
- Jetty 9.4.42 -> 9.4.23
- GraphQL-Java 16.2 -> 17.1
- gRPC-Java 1.38.1 -> 1.40.0
  - protobuf-java 3.12.0 -> 3.17.2
  - protobuf-gradle-plugin 0.8.13 -> 0.8.17
- Kotlin 1.5.10 -> 1.5.21
  - kotlinx-coroutines-core 1.5.0 -> 1.5.1
- Logback 1.2.3 -> 1.2.5
- Micrometer 1.7.1 -> 1.7.3
- Netty 4.1.65 -> 4.1.67
  - tcnative-boringssl-static 2.0.39 -> 2.0.40
  - transport-native-io_uring 0.0.5 -> 0.0.8
- java-jwt 3.16.0 -> 3.18.1
- Reactor 3.4.7 -> 3.4.9
- RESTeasy 4.6.1 -> 4.7.1
- RxJava 3.0.13 -> 3.1.0
- scala-collection-compat 2.4.4 -> 2.5.0
- ScalaPB 0.11.4 -> 0.11.5
- ScalaPB json4s 0.11.1 -> 0.12.0
- SLF4J 1.7.31 -> 1.7.32
- Spring 5.3.8 -> 5.3.9
- Spring Boot 2.5.2 -> 2.5.3
- ZooKeeper 3.6.2 -> 3.6.3
- Build
  - Checkstyle 8.43 -> 8.45.1
  - Error Prone 2.7.1 -> 2.8.1
  - Eureka 1.10.15 -> 1.10.16
  - Finagle 21.6.0 -> 21.8.0
  - Gradle 7.1 -> 7.1.1
  - graphql-dgs-client 4.3.1 -> 4.5.1
  - graphql-kotlin 4.1.1 -> 5.0.0-alpha.3
  - groovy-xml 3.0.5 -> 3.0.8
  - jmh 1.32 -> 1.33
  - jsoup 1.13.1 -> 1.14.2
  - MUnit 0.7.26 -> 0.7.28
  - Proguard 7.1.0 -> 7.1.1
  - Reactor gRPC 1.0.1 -> 1.1.0
  - reactor-kotlin-extensions 1.1.3 -> 1.1.4
- Shaded
  - copmletable-futures 0.3.4 -> 0.3.5
- Miscellaneous
  - Add a missing Brotli's license
  - Add a workaround for a configuration error of gradle-proto-plugin
    - google/protobuf-gradle-plugin#391
@ejona86 ejona86 removed this from the Next milestone May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants