openapi-processor / openapi-processor-spring

an OpenAPI 3.0 & 3.1 interface & model java code generator for Spring Boot
https://docs.openapiprocessor.io
Apache License 2.0
35 stars 9 forks source link

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

Open eekboom opened 2 weeks ago

eekboom commented 2 weeks ago

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 commented 2 weeks ago

Haven't seen this one, investigating...

hauner commented 2 weeks ago

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 https://github.com/google/guava/issues/6801#issuecomment-1806354453

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 commented 2 weeks ago

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

eekboom commented 2 weeks ago

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