From 2ab59fa39373d64b77ad7245ec6483424b8e981a Mon Sep 17 00:00:00 2001 From: leonid Date: Mon, 30 Sep 2024 20:12:17 +0200 Subject: [PATCH] [Kotlin Server] Update Ktor to latest version; move config to kts --- .../languages/KotlinServerCodegen.java | 15 ++- .../libraries/ktor/README.mustache | 4 +- .../libraries/ktor/build.gradle.kts.mustache | 61 ++++++++++++ .../libraries/ktor/build.gradle.mustache | 96 ------------------- .../libraries/ktor/gradle-wrapper.properties | 5 + .../libraries/ktor/gradle.properties | 5 +- .../.openapi-generator/FILES | 3 +- .../kotlin-server-modelMutable/README.md | 4 +- .../build.gradle.kts | 41 ++++++++ .../gradle.properties | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 5 + .../ktor/.openapi-generator/FILES | 3 +- .../petstore/kotlin-server/ktor/README.md | 4 +- .../petstore/kotlin-server/ktor/build.gradle | 74 -------------- .../kotlin-server/ktor/build.gradle.kts | 41 ++++++++ .../kotlin-server/ktor/gradle.properties | 5 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 17 files changed, 188 insertions(+), 185 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache delete mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache create mode 100644 modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle-wrapper.properties create mode 100644 samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts create mode 100644 samples/server/petstore/kotlin-server-modelMutable/gradle/wrapper/gradle-wrapper.properties delete mode 100644 samples/server/petstore/kotlin-server/ktor/build.gradle create mode 100644 samples/server/petstore/kotlin-server/ktor/build.gradle.kts diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java index 1db516c090d7..2fc9871b9f59 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinServerCodegen.java @@ -272,13 +272,13 @@ public void processOpts() { supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); - if (library.equals(Constants.KTOR)) { + if (isKtor()) { supportingFiles.add(new SupportingFile("Dockerfile.mustache", "", "Dockerfile")); } String gradleBuildFile = "build.gradle"; - if (isJavalin()) { + if (isJavalin() || isKtor()) { gradleBuildFile = "build.gradle.kts"; } @@ -286,7 +286,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle")); supportingFiles.add(new SupportingFile("gradle.properties", "", "gradle.properties")); - if (library.equals(Constants.KTOR)) { + if (isKtor()) { supportingFiles.add(new SupportingFile("AppMain.kt.mustache", packageFolder, "AppMain.kt")); supportingFiles.add(new SupportingFile("Configuration.kt.mustache", packageFolder, "Configuration.kt")); @@ -300,6 +300,11 @@ public void processOpts() { final String infrastructureFolder = (sourceFolder + File.separator + packageName + File.separator + "infrastructure").replace(".", File.separator); supportingFiles.add(new SupportingFile("ApiKeyAuth.kt.mustache", infrastructureFolder, "ApiKeyAuth.kt")); + + if (!getOmitGradleWrapper()) { + supportingFiles.add(new SupportingFile("gradle-wrapper.properties", "gradle" + File.separator + "wrapper", "gradle-wrapper.properties")); + } + } else if (isJavalin()) { supportingFiles.add(new SupportingFile("Main.kt.mustache", packageFolder, "Main.kt")); apiTemplateFiles.put("service.mustache", "Service.kt"); @@ -412,4 +417,8 @@ public void setReturnContainer(final String returnContainer) { private boolean isJavalin() { return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library); } + + private boolean isKtor() { + return Constants.KTOR.equals(library); + } } diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/README.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/README.mustache index 5c3a10ef2121..24333d99ccbd 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/README.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/README.mustache @@ -8,8 +8,8 @@ Generated by OpenAPI Generator {{generatorVersion}}{{^hideGenerationTimestamp}} ## Requires -* Kotlin 1.7.20 -* Gradle 7.4.2 +* Kotlin 2.0.20 +* Gradle 8.10.2 ## Build diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache new file mode 100644 index 000000000000..3dc3dd38f043 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.kts.mustache @@ -0,0 +1,61 @@ + +val kotlin_version: String by project +val logback_version: String by project + +group = "{{groupId}}" +version = "{{artifactVersion}}" + +plugins { + kotlin("jvm") version "2.0.20" + id("io.ktor.plugin") version "2.3.12" +} + +application { + mainClass.set("io.ktor.server.netty.EngineMain") + + val isDevelopment: Boolean = project.ext.has("development") + applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("ch.qos.logback:logback-classic:$logback_version") +{{#hasAuthMethods}} + implementation("com.typesafe:config:1.4.1") +{{/hasAuthMethods}} + implementation("io.ktor:ktor-server-auth") +{{#hasAuthMethods}} + implementation("io.ktor:ktor-client-apache") +{{/hasAuthMethods}} +{{#featureAutoHead}} + implementation("io.ktor:ktor-server-auto-head-response") +{{/featureAutoHead}} + implementation("io.ktor:ktor-server-default-headers") + implementation("io.ktor:ktor-server-content-negotiation") + implementation("io.ktor:ktor-serialization-gson") +{{#featureResources}} + implementation("io.ktor:ktor-server-resources") +{{/featureResources}} +{{#featureHSTS}} + implementation("io.ktor:ktor-server-hsts") +{{/featureHSTS}} +{{#featureCORS}} + implementation("io.ktor:ktor-server-cors") +{{/featureCORS}} +{{#featureConditionalHeaders}} + implementation("io.ktor:ktor-server-conditional-headers") +{{/featureConditionalHeaders}} +{{#featureCompression}} + implementation("io.ktor:ktor-server-compression") +{{/featureCompression}} +{{#featureMetrics}} + implementation("io.dropwizard.metrics:metrics-core:4.1.18") + implementation("io.ktor:ktor-server-metrics") +{{/featureMetrics}} + implementation("io.ktor:ktor-server-netty") + + testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") +} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache deleted file mode 100644 index 114a9a375592..000000000000 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/build.gradle.mustache +++ /dev/null @@ -1,96 +0,0 @@ -group "{{groupId}}" -version "{{artifactVersion}}" -{{^omitGradleWrapper}} - -wrapper { - gradleVersion = "7.4.2" - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} -{{/omitGradleWrapper}} - -buildscript { - ext.kotlin_version = "1.7.20" - ext.ktor_version = "2.2.1" - ext.shadow_version = "6.1.0" - - repositories { - maven { url "https://repo1.maven.org/maven2" } - maven { url "https://plugins.gradle.org/m2/" } - } - dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") - classpath("com.github.jengelman.gradle.plugins:shadow:$shadow_version") - } -} - -apply plugin: "java" -apply plugin: "kotlin" -apply plugin: "application" - -mainClassName = "io.ktor.server.netty.DevelopmentEngine" - -// Initialization order with shadow 2.0.1 and Gradle 6.9 is weird. -// See https://github.com/johnrengelman/shadow/issues/336#issuecomment-355402508 -apply plugin: "com.github.johnrengelman.shadow" - -sourceCompatibility = 1.8 - -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -shadowJar { - baseName = "{{artifactId}}" - classifier = null - version = null -} - -repositories { - maven { setUrl("https://repo1.maven.org/maven2") } - maven { setUrl("https://dl.bintray.com/kotlin/ktor") } - maven { setUrl("https://dl.bintray.com/kotlin/kotlinx") } -} - -dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") - implementation("ch.qos.logback:logback-classic:1.2.9") -{{#hasAuthMethods}} - implementation("com.typesafe:config:1.4.1") -{{/hasAuthMethods}} - implementation("io.ktor:ktor-server-auth:$ktor_version") -{{#hasAuthMethods}} - implementation("io.ktor:ktor-client-apache:$ktor_version") -{{/hasAuthMethods}} -{{#featureAutoHead}} - implementation("io.ktor:ktor-server-auto-head-response:$ktor_version") -{{/featureAutoHead}} - implementation("io.ktor:ktor-server-default-headers:$ktor_version") - implementation("io.ktor:ktor-server-content-negotiation:$ktor_version") - implementation("io.ktor:ktor-serialization-gson:$ktor_version") -{{#featureResources}} - implementation("io.ktor:ktor-server-resources:$ktor_version") -{{/featureResources}} -{{#featureHSTS}} - implementation("io.ktor:ktor-server-hsts:$ktor_version") -{{/featureHSTS}} -{{#featureCORS}} - implementation("io.ktor:ktor-server-cors:$ktor_version") -{{/featureCORS}} -{{#featureConditionalHeaders}} - implementation("io.ktor:ktor-server-conditional-headers:$ktor_version") -{{/featureConditionalHeaders}} -{{#featureCompression}} - implementation("io.ktor:ktor-server-compression:$ktor_version") -{{/featureCompression}} -{{#featureMetrics}} - implementation("io.dropwizard.metrics:metrics-core:4.1.18") - implementation("io.ktor:ktor-server-metrics:$ktor_version") -{{/featureMetrics}} - implementation("io.ktor:ktor-server-netty:$ktor_version") - - testImplementation("junit:junit:4.13.2") -} diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle-wrapper.properties b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle-wrapper.properties new file mode 100644 index 000000000000..18330fcba804 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties index 5f1ed7bbe024..d507b58c1c87 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties +++ b/modules/openapi-generator/src/main/resources/kotlin-server/libraries/ktor/gradle.properties @@ -1 +1,4 @@ -org.gradle.caching=true \ No newline at end of file +kotlin.code.style=official +ktor_version=2.3.12 +kotlin_version=2.0.20 +logback_version=1.4.14 \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server-modelMutable/.openapi-generator/FILES b/samples/server/petstore/kotlin-server-modelMutable/.openapi-generator/FILES index 79943171ff21..52c6d592e8f2 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-server-modelMutable/.openapi-generator/FILES @@ -1,7 +1,8 @@ Dockerfile README.md -build.gradle +build.gradle.kts gradle.properties +gradle/wrapper/gradle-wrapper.properties settings.gradle src/main/kotlin/org/openapitools/server/AppMain.kt src/main/kotlin/org/openapitools/server/Configuration.kt diff --git a/samples/server/petstore/kotlin-server-modelMutable/README.md b/samples/server/petstore/kotlin-server-modelMutable/README.md index 789760e26224..9657f4b4698e 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/README.md +++ b/samples/server/petstore/kotlin-server-modelMutable/README.md @@ -6,8 +6,8 @@ Generated by OpenAPI Generator 7.9.0-SNAPSHOT. ## Requires -* Kotlin 1.7.20 -* Gradle 7.4.2 +* Kotlin 2.0.20 +* Gradle 8.10.2 ## Build diff --git a/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts b/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts new file mode 100644 index 000000000000..fb35b77164a8 --- /dev/null +++ b/samples/server/petstore/kotlin-server-modelMutable/build.gradle.kts @@ -0,0 +1,41 @@ + +val kotlin_version: String by project +val logback_version: String by project + +group = "org.openapitools" +version = "1.0.0" + +plugins { + kotlin("jvm") version "2.0.20" + id("io.ktor.plugin") version "2.3.12" +} + +application { + mainClass.set("io.ktor.server.netty.EngineMain") + + val isDevelopment: Boolean = project.ext.has("development") + applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("ch.qos.logback:logback-classic:$logback_version") + implementation("com.typesafe:config:1.4.1") + implementation("io.ktor:ktor-server-auth") + implementation("io.ktor:ktor-client-apache") + implementation("io.ktor:ktor-server-auto-head-response") + implementation("io.ktor:ktor-server-default-headers") + implementation("io.ktor:ktor-server-content-negotiation") + implementation("io.ktor:ktor-serialization-gson") + implementation("io.ktor:ktor-server-resources") + implementation("io.ktor:ktor-server-hsts") + implementation("io.ktor:ktor-server-compression") + implementation("io.dropwizard.metrics:metrics-core:4.1.18") + implementation("io.ktor:ktor-server-metrics") + implementation("io.ktor:ktor-server-netty") + + testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") +} diff --git a/samples/server/petstore/kotlin-server-modelMutable/gradle.properties b/samples/server/petstore/kotlin-server-modelMutable/gradle.properties index 5f1ed7bbe024..d507b58c1c87 100644 --- a/samples/server/petstore/kotlin-server-modelMutable/gradle.properties +++ b/samples/server/petstore/kotlin-server-modelMutable/gradle.properties @@ -1 +1,4 @@ -org.gradle.caching=true \ No newline at end of file +kotlin.code.style=official +ktor_version=2.3.12 +kotlin_version=2.0.20 +logback_version=1.4.14 \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server-modelMutable/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-server-modelMutable/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..18330fcba804 --- /dev/null +++ b/samples/server/petstore/kotlin-server-modelMutable/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/samples/server/petstore/kotlin-server/ktor/.openapi-generator/FILES b/samples/server/petstore/kotlin-server/ktor/.openapi-generator/FILES index 79943171ff21..52c6d592e8f2 100644 --- a/samples/server/petstore/kotlin-server/ktor/.openapi-generator/FILES +++ b/samples/server/petstore/kotlin-server/ktor/.openapi-generator/FILES @@ -1,7 +1,8 @@ Dockerfile README.md -build.gradle +build.gradle.kts gradle.properties +gradle/wrapper/gradle-wrapper.properties settings.gradle src/main/kotlin/org/openapitools/server/AppMain.kt src/main/kotlin/org/openapitools/server/Configuration.kt diff --git a/samples/server/petstore/kotlin-server/ktor/README.md b/samples/server/petstore/kotlin-server/ktor/README.md index 789760e26224..9657f4b4698e 100644 --- a/samples/server/petstore/kotlin-server/ktor/README.md +++ b/samples/server/petstore/kotlin-server/ktor/README.md @@ -6,8 +6,8 @@ Generated by OpenAPI Generator 7.9.0-SNAPSHOT. ## Requires -* Kotlin 1.7.20 -* Gradle 7.4.2 +* Kotlin 2.0.20 +* Gradle 8.10.2 ## Build diff --git a/samples/server/petstore/kotlin-server/ktor/build.gradle b/samples/server/petstore/kotlin-server/ktor/build.gradle deleted file mode 100644 index bd883dc22910..000000000000 --- a/samples/server/petstore/kotlin-server/ktor/build.gradle +++ /dev/null @@ -1,74 +0,0 @@ -group "org.openapitools" -version "1.0.0" - -wrapper { - gradleVersion = "7.4.2" - distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" -} - -buildscript { - ext.kotlin_version = "1.7.20" - ext.ktor_version = "2.2.1" - ext.shadow_version = "6.1.0" - - repositories { - maven { url "https://repo1.maven.org/maven2" } - maven { url "https://plugins.gradle.org/m2/" } - } - dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version") - classpath("com.github.jengelman.gradle.plugins:shadow:$shadow_version") - } -} - -apply plugin: "java" -apply plugin: "kotlin" -apply plugin: "application" - -mainClassName = "io.ktor.server.netty.DevelopmentEngine" - -// Initialization order with shadow 2.0.1 and Gradle 6.9 is weird. -// See https://github.com/johnrengelman/shadow/issues/336#issuecomment-355402508 -apply plugin: "com.github.johnrengelman.shadow" - -sourceCompatibility = 1.8 - -compileKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -compileTestKotlin { - kotlinOptions.jvmTarget = "1.8" -} - -shadowJar { - baseName = "kotlin-server" - classifier = null - version = null -} - -repositories { - maven { setUrl("https://repo1.maven.org/maven2") } - maven { setUrl("https://dl.bintray.com/kotlin/ktor") } - maven { setUrl("https://dl.bintray.com/kotlin/kotlinx") } -} - -dependencies { - implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version") - implementation("ch.qos.logback:logback-classic:1.2.9") - implementation("com.typesafe:config:1.4.1") - implementation("io.ktor:ktor-server-auth:$ktor_version") - implementation("io.ktor:ktor-client-apache:$ktor_version") - implementation("io.ktor:ktor-server-auto-head-response:$ktor_version") - implementation("io.ktor:ktor-server-default-headers:$ktor_version") - implementation("io.ktor:ktor-server-content-negotiation:$ktor_version") - implementation("io.ktor:ktor-serialization-gson:$ktor_version") - implementation("io.ktor:ktor-server-resources:$ktor_version") - implementation("io.ktor:ktor-server-hsts:$ktor_version") - implementation("io.ktor:ktor-server-compression:$ktor_version") - implementation("io.dropwizard.metrics:metrics-core:4.1.18") - implementation("io.ktor:ktor-server-metrics:$ktor_version") - implementation("io.ktor:ktor-server-netty:$ktor_version") - - testImplementation("junit:junit:4.13.2") -} diff --git a/samples/server/petstore/kotlin-server/ktor/build.gradle.kts b/samples/server/petstore/kotlin-server/ktor/build.gradle.kts new file mode 100644 index 000000000000..fb35b77164a8 --- /dev/null +++ b/samples/server/petstore/kotlin-server/ktor/build.gradle.kts @@ -0,0 +1,41 @@ + +val kotlin_version: String by project +val logback_version: String by project + +group = "org.openapitools" +version = "1.0.0" + +plugins { + kotlin("jvm") version "2.0.20" + id("io.ktor.plugin") version "2.3.12" +} + +application { + mainClass.set("io.ktor.server.netty.EngineMain") + + val isDevelopment: Boolean = project.ext.has("development") + applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("ch.qos.logback:logback-classic:$logback_version") + implementation("com.typesafe:config:1.4.1") + implementation("io.ktor:ktor-server-auth") + implementation("io.ktor:ktor-client-apache") + implementation("io.ktor:ktor-server-auto-head-response") + implementation("io.ktor:ktor-server-default-headers") + implementation("io.ktor:ktor-server-content-negotiation") + implementation("io.ktor:ktor-serialization-gson") + implementation("io.ktor:ktor-server-resources") + implementation("io.ktor:ktor-server-hsts") + implementation("io.ktor:ktor-server-compression") + implementation("io.dropwizard.metrics:metrics-core:4.1.18") + implementation("io.ktor:ktor-server-metrics") + implementation("io.ktor:ktor-server-netty") + + testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version") +} diff --git a/samples/server/petstore/kotlin-server/ktor/gradle.properties b/samples/server/petstore/kotlin-server/ktor/gradle.properties index 5f1ed7bbe024..d507b58c1c87 100644 --- a/samples/server/petstore/kotlin-server/ktor/gradle.properties +++ b/samples/server/petstore/kotlin-server/ktor/gradle.properties @@ -1 +1,4 @@ -org.gradle.caching=true \ No newline at end of file +kotlin.code.style=official +ktor_version=2.3.12 +kotlin_version=2.0.20 +logback_version=1.4.14 \ No newline at end of file diff --git a/samples/server/petstore/kotlin-server/ktor/gradle/wrapper/gradle-wrapper.properties b/samples/server/petstore/kotlin-server/ktor/gradle/wrapper/gradle-wrapper.properties index 92f06b50fd65..18330fcba804 100644 --- a/samples/server/petstore/kotlin-server/ktor/gradle/wrapper/gradle-wrapper.properties +++ b/samples/server/petstore/kotlin-server/ktor/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists