OpenAPITools / OpenAPITools/openapi-generator
[BUG][GRADLE] The presence of setters in GenerateTask and ValidateTask prevent plugin use from Gradle build scripts written in Kotlin
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Invoking the openapi-generator-gradle-plugin from a Gradle build script written in Kotlin results in Gradle errors that cause the build to fail.
openapi-generator version
5.2.1
OpenAPI declaration file content or url
Not applicable, this is a bug in openapi-generator-gradle-plugin that prevents validation and generation tasks from executing during build when the gradle build script is written in kotlin
Any openapi declaration file can be used
Generation Details
Not applicable, this is a bug in the gradle plugin, not the generator
Steps to reproduce
- Create a gradle (I used version 7.2) project with a build.gradle.kts (this is a gradle build script written in kotlin) similar to the following:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.openapitools.generator.gradle.plugin.tasks.ValidateTask
plugins {
java
val kotlinVersion = "1.5.31"
kotlin("jvm") version kotlinVersion
id("org.openapi.generator") version ("5.2.1")
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
}
tasks {
named<Test>("test") {
useJUnitPlatform()
dependsOn("openApiValidate")
}
named<ValidateTask>("openApiValidate") {
inputSpec.value("$rootDir/openapi.yml") // any openapi.yml can be provided
recommend.value(true)
}
}
- execute ./gradlew test
- The build will fail with the following errors:
* What went wrong:
Some problems were found with the configuration of task ':openApiValidate' (type 'ValidateTask').
- In plugin 'org.openapi.generator' type 'org.openapitools.generator.gradle.plugin.tasks.ValidateTask' property 'inputSpec' of mutable type 'org.gradle.api.provider.Property' is writable.
Reason: Properties of type 'org.gradle.api.provider.Property' are already mutable.
Possible solution: Remove the 'setInputSpec' method.
Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#mutable_type_with_setter for more details about this problem.
- In plugin 'org.openapi.generator' type 'org.openapitools.generator.gradle.plugin.tasks.ValidateTask' property 'recommend' of mutable type 'org.gradle.api.provider.Property' is writable.
Reason: Properties of type 'org.gradle.api.provider.Property' are already mutable.
Possible solution: Remove the 'setRecommend' method.
Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#mutable_type_with_setter for more details about this problem.
Related issues/PRs
Another issue exists using different versions of Gradle and Openapi Generator Gradle Plugin, but does not suggest a fix.
https://github.com/OpenAPITools/openapi-generator/issues/9778
Suggest a fix
Gradle doesn't like for Task classes to contain setters. Both org.openapitools.generator.gradle.plugin.tasks.ValidateTask and org.openapitools.generator.gradle.plugin.tasks.GenerateTask contain the following snippet of offending code:
@Suppress("unused")
@set:Option(option = "input", description = "The input specification.")
@Internal
var input: String? = null
set(value) {
inputSpec.set(value)
}
This code exists both in 5.2.1 and in master.
I removed this code from both tasks in my local build of openapi-generator-gradle-plugin and published to my local maven repo. Using the my modified version of the plugin, I am now able to execute both tasks from a gradle build script written in kotlin.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the GenerateTask and ValidateTask classes, focusing on the setter snippets shown in the issue and how their inputSpec and recommend properties are declared. Reproduce the problem with the provided Kotlin Gradle build script and run ./gradlew test; done means both tasks can be configured and executed without Gradle's mutable-property validation errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100