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

Regression: Variant Ambiguity error during Gradle dependency resolution when apply the plugin lazily #351

Closed
stefanroeck opened this issue Dec 5, 2024 · 4 comments · Fixed by #353
Labels
bug Something isn't working

Comments

@stefanroeck
Copy link

What version of OpenRewrite are you using?

I am using

  • OpenRewrite Gradle plugin v6.28.1

How are you running OpenRewrite?

I am using the Gradle plugin, and my project is a multi module project.

See a reproducer here: https://github.com/stefanroeck/openrewrite_reproducer

  • checkout the reproducer repo
  • run ./gradlew build

In this project, two submodules exist where the one depends on the other. The open-rewrite plugin is applied lazily (in the original setup, we have hundreds of submodules and to this for maintenance reasons for many of such plugins).

I believe this has been introduced with 147c7ef

What did you expect to see?

  • Build just runs fine

What did you see instead?

Error message

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':SubModule2:test'.
> Could not resolve all dependencies for configuration ':SubModule2:testRuntimeClasspath'.
   > Could not resolve project :SubModule1.
     Required by:
         project :SubModule2
      > The consumer was configured to find a library for use during runtime, compatible with Java 17, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally. However we cannot choose between the following variants of project :SubModule1:
          - rewrite
          - runtimeElements
        All of them match the consumer attributes:
          - Variant 'rewrite' capability 'openRewriteReproducer:SubModule1:unspecified' declares a library for use during runtime, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally:
              - Unmatched attribute:
                  - Doesn't say anything about its target Java version (required compatibility with Java 17)
          - Variant 'runtimeElements' capability 'openRewriteReproducer:SubModule1:unspecified' declares a library for use during runtime, compatible with Java 17, packaged as a jar, and its dependencies declared externally:
              - Unmatched attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)

* Try:
> Ambiguity errors are explained in more detail at https://docs.gradle.org/8.11.1/userguide/variant_model.html#sub:variant-ambiguity.
> Review the variant matching algorithm at https://docs.gradle.org/8.11.1/userguide/variant_attributes.html#sec:abm_algorithm.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
@stefanroeck stefanroeck added the bug Something isn't working label Dec 5, 2024
@timtebeek
Copy link
Contributor

hi! Did you already explore the work being done in #349 to revert some of those changes?

Curious if from your perspective that would resolve this issue as well.

@nicolasb29
Copy link
Contributor

hi! Did you already explore the work being done in #349 to revert some of those changes?

Curious if from your perspective that would resolve this issue as well.

It seems that the cause is to add attributes to Configuration rewriteConf. https://github.com/openrewrite/rewrite-gradle-plugin/blob/main/plugin/src/main/java/org/openrewrite/gradle/RewritePlugin.java#L88

@stefanroeck
Copy link
Author

Curious if from your perspective that would resolve this issue as well.

Not sure, is there a snapshot build published somewhere that I could use for quick verification?

@MartinAhrer
Copy link

MartinAhrer commented Dec 9, 2024

I experience the same issue but I think it is not related to multi-module.

I'm using Java 21, Gradle 8.11, open-rewrite = "6.28.1" and dependency management is done through a TOML file.

You can reproduce the issue with the repo I provide for that case at https://github.com/MartinAhrer/issue-openrewrite-gradle-variant.

Run ./gradlew check and the produced error log will be something like the following

Could not determine the dependencies of task ':test'.
> Could not resolve all dependencies for configuration ':testRuntimeClasspath'.
   > Could not resolve root project :.
     Required by:
         root project :
      > The consumer was configured to find a library for use during runtime, compatible with Java 21, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally. However we cannot choose between the following variants of root project ::
          - rewrite
          - runtimeElements
        All of them match the consumer attributes:
          - Variant 'rewrite' capability 'at.martinahrer:modulith:0.0.1-SNAPSHOT' declares a library for use during runtime, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally:
              - Unmatched attribute:
                  - Doesn't say anything about its target Java version (required compatibility with Java 21)
          - Variant 'runtimeElements' capability 'at.martinahrer:modulith:0.0.1-SNAPSHOT' declares a library for use during runtime, compatible with Java 21, packaged as a jar, and its dependencies declared externally:
              - Unmatched attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)

* Try:
> Ambiguity errors are explained in more detail at https://docs.gradle.org/8.11.1/userguide/variant_model.html#sub:variant-ambiguity.
> Review the variant matching algorithm at https://docs.gradle.org/8.11.1/userguide/variant_attributes.html#sec:abm_algorithm.

The same repository still works with 6.27.2!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants