Openapi-generator: [BUG][Kotlin] With version 4.1.1 I cannot build my kotlin server stubs anymore, was working with 4.1.0

Created on 1 Sep 2019  路  26Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] What's the version of OpenAPI Generator used?
    4.1.1
Description

I am using the openapi gradle plugin.
If I switch to version 4.1.1, it stops working with unknown error. I have to rollback the version to 4.1.0 to make it work again.
The yaml file is validated automatically via gradle.
I get this exception when trying to generate the server stubs:

`FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':buildKotlinServer'.

    java.lang.UnsupportedOperationException (no error message)

  • Try:
    Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Exception is:
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':buildKotlinServer'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:166)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:163)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:156)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
    at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
    at org.gradle.api.internal.tasks.execution.StartSnapshotTaskInputsBuildOperationTaskExecuter.execute(StartSnapshotTaskInputsBuildOperationTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
    at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
    at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
    at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
    Caused by: java.lang.UnsupportedOperationException
    at com.google.common.collect.ImmutableMap.put(ImmutableMap.java:450)
    at org.openapitools.codegen.config.WorkflowSettings$Builder.withSystemProperty(WorkflowSettings.java:465)
    at org.openapitools.codegen.config.CodegenConfigurator.addSystemProperty(CodegenConfigurator.java:141)
    at org.openapitools.generator.gradle.plugin.tasks.GenerateTask.doWork(GenerateTask.kt:398)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:49)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:42)
    at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:717)
    at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:684)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:476)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
    at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
    at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:461)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:444)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:93)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:237)
    at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
    at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
    at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
    at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
    at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
    at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
    at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
    at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
    at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
    at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
    at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:208)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
    at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
    at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
    at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
    at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
    at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:76)
    at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
    at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
    at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:69)
    at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:47)
    at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:140)
    ... 35 more
    `

openapi-generator version

4.1.1

OpenAPI declaration file content or url

Just use the standard Pet API yaml

Command line used for generation

Kotlin server config file server-api-config.json

{ "sourceFolder" : "", "packageName" : "com.xxx.yyy.api.autogenerated", "groupId": "com.xxx.yyy.api", "featureCors" : false, "featureAutoHead" : false, "featureConditionalHeaders" : false, "featureHSTS" : false, "featureCompression" : false }

Steps to reproduce

gradle task used:

task buildKotlinServer(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
    generatorName = "kotlin-server"
    inputSpec = "$stageDir/docs/api.yaml"
    outputDir = "$srcDir/main/kotlin"
    templateDir = "$srcDir/main/mustache/kotlin-server"
    configFile = "$rootDir/server-api-config.json"
    supportingFilesConstrainedTo = [
            "Paths.kt"
    ]
    systemProperties = [
            models: "",
            apis  : "",
    ]
}
Bug

Most helpful comment

@t2y I've opened #4447. Thank you for the investigative work you did in this issue, it helped track down the cause very quickly.

All 26 comments

What about doing a git bisect to identify the commit causing the issue?

Ref: https://www.metaltoad.com/blog/beginners-guide-git-bisect-process-elimination

We just release v4.1.2. Please give it a try to see if it works for you.

I tried 4.1.2 and 4.1.3 and I get the same issue.
I was really wonder what this can be because the error doesn't suggest much.

I think something is wrong with this part:

    systemProperties = [
            apis  : "",
            models: ""
    ]

Because if I remove it it goes further, but I need it and it's explained here

Caused by: java.lang.UnsupportedOperationException
        at com.google.common.collect.ImmutableMap.put(ImmutableMap.java:450)
        at org.openapitools.codegen.config.WorkflowSettings$Builder.withSystemProperty(WorkflowSettings.java:465)
        at org.openapitools.codegen.config.CodegenConfigurator.addSystemProperty(CodegenConfigurator.java:141)
        at org.openapitools.generator.gradle.plugin.tasks.GenerateTask.doWork(GenerateTask.kt:404)

Maybe, it has to do with the fact you guys are trying to use the map inappropriately in this case.

And it doesn't matter, whatever i put there it doesn't work:

    systemProperties = [
            apis  : "aa",
            models: "aa,aaa"
    ]

also this, not working

    systemProperties = [
            apis  : "false",
            models: "false"
    ]

I use the gradle plugin for Java (spring) and had the same issue. This is an error with 4.1.3 on my environment.

$ gradle clean openApiGenerate --stacktrace
...
Caused by: java.lang.UnsupportedOperationException
        at com.google.common.collect.ImmutableMap.put(ImmutableMap.java:450)
        at org.openapitools.codegen.config.WorkflowSettings$Builder.withSystemProperty(WorkflowSettings.java:465)
        at org.openapitools.codegen.config.CodegenConfigurator.addSystemProperty(CodegenConfigurator.java:141)
        at org.openapitools.generator.gradle.plugin.tasks.GenerateTask.doWork(GenerateTask.kt:404)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)

Something is off indeed, I could never upgrade anymore since 4.1.0 :(

What about using git bisect to identify the commit introducing the issue?

@wing328 I'm going to try git bisect, but I cannot build openapi-generator-gradle-plugin.jar as below.

$ mvn clean package -DskipTests
[INFO] openapi-generator (maven-plugin)                          [maven-plugin]
[INFO] openapi-generator-gradle-plugin (maven wrapper)                    [pom]
$ find modules -name "openapi-generator-*.jar"
modules/openapi-generator-core/target/openapi-generator-core-4.1.1-SNAPSHOT.jar
modules/openapi-generator-maven-plugin/target/openapi-generator-maven-plugin-4.1.1-SNAPSHOT.jar
modules/openapi-generator-maven-plugin/target/lib/openapi-generator-core-4.1.1-SNAPSHOT.jar
modules/openapi-generator-maven-plugin/target/lib/openapi-generator-4.1.1-SNAPSHOT.jar
modules/openapi-generator-online/target/openapi-generator-online.jar
modules/openapi-generator-online/target/lib/openapi-generator-core-4.1.1-SNAPSHOT.jar
modules/openapi-generator-online/target/lib/openapi-generator-4.1.1-SNAPSHOT.jar
modules/openapi-generator-cli/target/lib/openapi-generator-core-4.1.1-SNAPSHOT.jar
modules/openapi-generator-cli/target/lib/openapi-generator-4.1.1-SNAPSHOT.jar
modules/openapi-generator-cli/target/openapi-generator-cli.jar
modules/openapi-generator-gradle-plugin/target/lib/openapi-generator-core-4.1.1-SNAPSHOT.jar
modules/openapi-generator-gradle-plugin/target/lib/openapi-generator-4.1.1-SNAPSHOT.jar
modules/openapi-generator/target/openapi-generator-4.1.1-SNAPSHOT.jar
modules/openapi-generator/target/openapi-generator-4.1.1-SNAPSHOT-tests.jar
modules/openapi-generator/target/lib/openapi-generator-core-4.1.1-SNAPSHOT.jar

Could you tell me how to build openapi-generator-gradle-plugin.jar or how to use any revision of openapi-generator-gradle-plugin on local environment?

I tried to build with gradle, but I couldn't.

$ cd modules/openapi-generator-gradle-plugin
$ gradle build

> Configure project :
WARNING: Unsupported Kotlin plugin version.
The `embedded-kotlin` and `kotlin-dsl` plugins rely on features of Kotlin `1.3.41` that might work differently than in the requested version `1.2.61`.

FAILURE: Build failed with an exception.

* Where:
Build file 'openapi-generator/modules/openapi-generator-gradle-plugin/build.gradle' line: 40

* What went wrong:
A problem occurred evaluating root project 'openapi-generator-gradle-plugin'.
> org.gradle.kotlin.dsl.support.EmbeddedKotlinProvider.pinDependenciesOn(Lorg/gradle/api/artifacts/Configuration;[Ljava/lang/String;)V

I changed kotlin version, but it seems this error is not related to.

$ git diff build.gradle
diff --git a/modules/openapi-generator-gradle-plugin/build.gradle b/modules/openapi-generator-gradle-plugin/build.gradle
index 442ad53675..fb6501969f 100644
--- a/modules/openapi-generator-gradle-plugin/build.gradle
+++ b/modules/openapi-generator-gradle-plugin/build.gradle
@@ -1,5 +1,5 @@
 buildscript {
-    ext.kotlin_version = '1.2.61'
+    ext.kotlin_version = '1.3.41'

@taf2 thanks for the details in troubleshooting the issue.

@jimschubert can you please take a look when you've time?

@jimschubert ping?

I read source code related to the error.

Caused by: java.lang.UnsupportedOperationException
        at com.google.common.collect.ImmutableMap.put(ImmutableMap.java:450)
        at org.openapitools.codegen.config.WorkflowSettings$Builder.withSystemProperty(WorkflowSettings.java:465)

I found ImmutableMap is abstract class and put() method throw UnsupportedOperationException by default.

@jimschubert for 4.1.1, DEFAULT_SYSTEM_PROPERTIES had changed to create from ImmutableMap. I wonder whether this change causes an issue?

    public static final ImmutableMap<String, String> DEFAULT_SYSTEM_PROPERTIES = ImmutableMap.of();

@wing328 I think this issue is not about kotlin, it's gradle plugin module. Could you update title and labels.

I found this error occurs when configFile is specified. I can generate the source code after I commented out configFile line. My openApiGenerate task is as below.

openApiGenerate {
    generatorName = 'spring'
    //configFile = 'spec/config.json'
    inputSpec = "${rootDir}/spec/openapi.yaml"
    outputDir = "${buildDir}/generated"
    configOptions = [
        dateLibrary: 'java8'
    ]
    systemProperties = [
        modelDocs: 'false'
    ]
    typeMappings = [...]
    importMappings = [...]
    skipValidateSpec = true
    logToStderr = true
    generateAliasAsModel = false
}

@t2y what version of Gradle are you using?

@jimschubert 5.6.3

$ gradle --version

------------------------------------------------------------
Gradle 5.6.3
------------------------------------------------------------

Build time:   2019-10-18 00:28:36 UTC
Revision:     bd168bbf5d152c479186a897f2cea494b7875d13

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          1.8.0_202 (Oracle Corporation 25.202-b08)
OS:           Mac OS X 10.14.6 x86_64

@t2y Thanks. I'll take a look. I think it's more that WorkflowSettings assigns builder.systemProperties to an immutable map rather than mutable, and only when invoking newBuilder(WorkflowSettings copy).

I asked for Gradle version because I thought it might be related to #4352, which is in current master. It's possible it could have been both issues. I'll open a PR for the WorkflowSettings issue in a bit.

@t2y I've opened #4447. Thank you for the investigative work you did in this issue, it helped track down the cause very quickly.

@jimschubert Thank you, too!

I've merged the fix, which includes unit test and Gradle sample:

task buildDotnetSdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask){
    generatorName = "csharp-netcore"
    inputSpec = "$rootDir/petstore-v3.0.yaml".toString()
    additionalProperties = [
            packageGuid: "{321C8C3F-0156-40C1-AE42-D59761FB9B6C}",
            useCompareNetObjects: "true"
    ]
    outputDir = "$buildDir/csharp-netcore".toString()
    systemProperties = [
            models: "",
            apis  : "",
    ]
}

This will be released with 4.2.1.

I'm happy to hear merging! By the way, how about adding a test case includes configFile line?

configFile = 'config.json'

@t2y configFile doesn't exist in the type fixed in that PR. It's only used at "entrypoints" such as CLI, Gradle Plugin and Maven Plugin to load into CodegenConfigurator (see GenerateTask).

Actual testing of config file loading is already done via unit testing (example) and "functional tests". For instance, it is done via CI for 75+ different generator/option combinations for all PRs and master builds. I think this sort of functional testing makes the most sense for the config file option. I assume the reason the systemProperties option was never unit tested is because it was only recently (~11 months ago) that this was changed to thread-local properties rather than mutating System.properties via #1598. A large part of why I extracted properties to WorkflowSettings and GeneratorSettings is to limit the scope of these behaviors and to make them more easily testable.

@jimschubert Thank you for the detail/background of systemProperties! I understood this issue is niche and has long story.

I could build my application with 4.2.1. Thank you!

Cool. Thanks for verifying!

@wing328 I've changed this back to the 4.2.1 milestone. I'm not sure why it was updated to 4.2.2 since it was included in the 4.2.1 release. Feel free to reopen and comment if you had additional work planned in relation to this bug.

Was this page helpful?
0 / 5 - 0 ratings