Skip to content

Commit

Permalink
[gradle plugin] Support Gradle 4.10 (OpenAPITools#1011)
Browse files Browse the repository at this point in the history
* Support Gradle 4.10

Gradle 4.10 is bundled with Kotlin 1.60 and Kotlin DSL 1.0-rc1. The new
Kotlin DSL isn't binary compatible with the `tasks` registration used in
this plugin.

Updating to Kotlin DSL 1.0-rc1 with no other changes would require users
to update to Gradle 4.10.

As a workaround, I've modified the tasks registration being done in
OpenApiGeneratorPlugin.kt, so rather than using the Kotlin DSL's invoke,
it creates tasks manually against the TasksContainer. This works locally
with Gradle 4.7+ for all scenarios in the sample (samples/local-spec).
There may be edge cases that I'm unaware of, and we may want to consider
defining the minimum supported Gradle version of 4.10 in the next major
version of openapi-generator-gradle-plugin if we experience those cases.

* Uncomment snapshots repo (commented it during local testing)

* update pom.xml for exec gradle plugin
  • Loading branch information
jimschubert authored Sep 12, 2018
1 parent f29ba97 commit 131cf94
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions modules/openapi-generator-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.2.41'
ext.kotlin_version = '1.2.60'
repositories {
mavenCentral()
maven {
Expand All @@ -14,7 +14,7 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "gradle.plugin.org.gradle.kotlin:gradle-kotlin-dsl-plugins:0.17.5"
classpath "gradle.plugin.org.gradle.kotlin:gradle-kotlin-dsl-plugins:1.0-rc-3"
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-rc-1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<artifactId>gradle-maven-plugin</artifactId>
<version>1.0.8</version>
<configuration>
<gradleVersion>4.7</gradleVersion>
<gradleVersion>4.10-rc-1</gradleVersion>
<args>
<arg>-P openApiGeneratorVersion=${project.version}</arg>
</args>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ gradle generateGoWithInvalidSpec
The samples can be tested against other versions of the plugin using the `openApiGeneratorVersion` property. For example:

```bash
gradle -PopenApiGeneratorVersion=3.2.3 openApiValidate
gradle -PopenApiGeneratorVersion=3.3.0 openApiValidate
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package org.openapitools.generator.gradle.plugin

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.invoke
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorGenerateExtension
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorMetaExtension
import org.openapitools.generator.gradle.plugin.extensions.OpenApiGeneratorValidateExtension
Expand Down Expand Up @@ -56,26 +55,29 @@ class OpenApiGeneratorPlugin : Plugin<Project> {

generate.outputDir.set("$buildDir/generate-resources/main")

tasks {
"openApiGenerators"(GeneratorsTask::class) {
tasks.apply {
create("openApiGenerators", GeneratorsTask::class.java) {
group = pluginGroup
description = "Lists generators available via Open API Generators."
}
"openApiMeta"(MetaTask::class) {

create("openApiMeta", MetaTask::class.java) {
group = pluginGroup
description = "Generates a new generator to be consumed via Open API Generator."

generatorName.set(meta.generatorName)
packageName.set(meta.packageName)
outputFolder.set(meta.outputFolder)
}
"openApiValidate"(ValidateTask::class) {

create("openApiValidate", ValidateTask::class.java) {
group = pluginGroup
description = "Validates an Open API 2.0 or 3.x specification document."

inputSpec.set(validate.inputSpec)
}
"openApiGenerate"(GenerateTask::class) {

create("openApiGenerate", GenerateTask::class.java) {
group = pluginGroup
description = "Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents."

Expand Down

0 comments on commit 131cf94

Please sign in to comment.