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

processSpring fails with "Cannot choose between the available variants of guava" #286

Open
eekboom opened this issue Aug 26, 2024 · 4 comments

Comments

@eekboom
Copy link

eekboom commented Aug 26, 2024

Trying to get started with code generation.
Created a new gradle subproject with my openapi.yaml and these files straight out of the docs:

build.gradle:

plugins {
    id 'io.openapiprocessor.openapi-processor' version '2023.2'
}

openapiProcessor {
    spring {
        processor 'io.openapiprocessor:openapi-processor-spring:2024.4'
        apiPath "$projectDir/src/api/openapi.yaml"
        targetDir "$projectDir/build/openapi"
        mapping "$projectDir/mapping.yaml"
        parser "INTERNAL"
    }
}

gradle.properties:

org.gradle.jvmargs= \
  --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
  --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

mapping.yaml

openapi-processor-mapping: v7

options:
  package-name: com.acme.foo
  model-name-suffix: Resource
  model-type: record
  enum-type: string
  one-of-interface: true
  bean-validation: jakarta
  generated-date: true
  format-code: true
  javadoc: true
  clear-target-dir: false

compatibility:
  bean-validation-valid-on-reactive: false
  identifier-word-break-from-digit-to-letter: false

map:
# java type mappings

When I run gradle processSpring, this ios the result:

Execution failed for task ':data_consumer:processSpring'.
> Could not resolve all files for configuration ':data_consumer:detachedConfiguration1'.
   > Could not find com.fasterxml.jackson.module:jackson-module-kotlin:.
     Required by:
         project :data_consumer > io.openapiprocessor:openapi-processor-spring:2024.4 > io.openapiprocessor:openapi-processor-core:2024.5
   > Could not resolve com.google.guava:guava:32.1.3-jre.
     Required by:
         project :data_consumer > io.openapiprocessor:openapi-processor-spring:2024.4 > io.openapiprocessor:openapi-processor-core:2024.5
      > Cannot choose between the available variants of com.google.guava:guava:33.2.1-jre
        The only attribute distinguishing these variants is 'org.gradle.jvm.environment'. Add this attribute to the consumer's configuration to resolve the ambiguity:
          - Value: 'android' selects variant: 'androidRuntimeElements'
          - Value: 'standard-jvm' selects variant: 'jreRuntimeElements'
> There is 1 more failure with an identical cause. 

I don't know how/where to add the standard-jvm setting.

gradle 8.9, Java 21

@hauner
Copy link
Member

hauner commented Aug 27, 2024

Haven't seen this one, investigating...

@hauner
Copy link
Member

hauner commented Aug 27, 2024

Unfortunately I can't reproduce the issue.

Is this an android project?

If so, could you create a minimal android project that shows the error? That would be very helpful to create fix for the issue. (I have never done anything with android).

Also, I found this google/guava#6801 (comment)

It says applying id("jvm-ecosystem")may fix the issue. It could be a workaround, but I don't know if this has any other effect on the build.

@eekboom
Copy link
Author

eekboom commented Aug 27, 2024

Thanks for your answer!
It's a standard JVM project (not android).
I'll try and create an example project.

@eekboom
Copy link
Author

eekboom commented Aug 27, 2024

Adding id("jvm-ecosystem") to the plugins { section fixed the issue. Thanks!
(I will still create an example project for you to check.)

hauner added a commit to openapi-processor/openapi-processor-base that referenced this issue Aug 29, 2024
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

No branches or pull requests

2 participants