OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Kotlin] [Gradle Plugin] [Android] Updating Gradle plugin from 5.0.0 -> 5.1.0 results in missing method

Open
#9,173 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Retrofit Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I am using the OpenApiGenerator via the Gradle plugin in my Kotlin Android project. I am running into an issue updating the version of the OpenAPI Generator Gradle plugin version from 5.0.0 -> 5.1.0. When I use 5.0.0, everything works fine. When I try to update to 5.1.0, I receive the following build errors:

A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
   > com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;

Unable to find method 'com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;'
com.google.common.collect.ImmutableList.toImmutableList()Ljava/util/stream/Collector;

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

My build.gradle file:

buildscript {

    ext {
        epoxy_version = '4.4.2'
        fragment_version = '1.3.1'
        hilt_version = '2.33-beta'
        jetpack_hilt_version = '1.0.0-alpha03'
        kotlin_coroutines_version = '1.3.9'
        kotlin_version = '1.4.31'
        moshi_version = '1.11.0'
        navigation_version = '2.3.4'
        ok_http_version = '5.0.0-alpha.2'
        retrofit_version = '2.9.0'
        room_version = '2.2.6'
    }

    repositories {
        google()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.google.gms:google-services:4.3.5"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.5.1"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
        classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
        classpath "org.openapitools:openapi-generator-gradle-plugin:5.1.0"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url "https://zendesk.jfrog.io/zendesk/repo" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

The plugin is configured like so:

App-level build.gradle

openApiGenerate {
    generatorName = "kotlin"
    inputSpec = "$projectDir/openapi-spec.json"
    ignoreFileOverride = "$projectDir/.openapi-generator-ignore"
    outputDir = "$buildDir/generated/openapi"
    apiPackage = "com.my.example.api.service"
    modelPackage = "com.my.example.api.model"
    configFile = "$projectDir/openapi-generator-config.json"
}

openapi-generator-config.json

{
  "apiSuffix": "Service",
  "collectionType": "list",
  "enumPropertyNaming": "UPPERCASE",
  "library": "jvm-retrofit2",
  "modelMutable": "false",
  "moshiCodeGen": "true",
  "packageName": "com.my.example.api",
  "parcelizeModels": "true",
  "sortModelPropertiesByRequiredFlag": "true",
  "sortParamsByRequiredFlag": "true",
  "useCoroutines": "true",
  "typeMappings": {
    "java.net.URI": "kotlin.String"
  }
}
Suggest a fix

If I keep everything the same, but add the following Guava dependency, everything seems to work.

 dependencies {
        ...
        classpath "org.openapitools:openapi-generator-gradle-plugin:5.1.0"
        classpath "com.google.guava:guava:30.1.1-jre"
    }

The only difference is some of my generated models switch from Set attributes to List attributes. This is fine, but worth calling out. I am not an expert on Gradle and I am not quite sure how the plugin works so I am not sure if this approach is correct or if it would have any side effects. Any help is greatly appreciated.

@Parcelize
@JsonClass(generateAdapter = true)
data class LessonUpdateRequest (
    ...
    @Json(name = "instructorsAttending")
    var instructorsAttending: kotlin.collections.Set<kotlin.Long>,
    ...

turns into:

@Parcelize
@JsonClass(generateAdapter = true)
data class LessonUpdateRequest (
    ...
    @Json(name = "instructorsAttending")
    var instructorsAttending: kotlin.collections.List<kotlin.Long>,
    ...
) : Parcelable

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the root and app-level build.gradle files and the openapi-generator-config.json shown in the report. Reproduce with the OpenAPI Generator Gradle plugin 5.1.0, Android Gradle plugin 4.1.3, and the listed classpath dependencies, then compare dependency resolution with and without Guava 30.1.1-jre. Done means the project configures successfully without an unintended workaround and generated collection types remain understood and consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java, kotlin
Domain
build-system, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.