Skip to content

[Kotlin Server] Update Ktor to latest version; move config to kts #19727

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/samples-kotlin-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
# - samples/server/petstore/kotlin-spring-default/**

env:
GRADLE_VERSION: 6.9
GRADLE_VERSION: 7.6.4

jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,21 +272,21 @@ 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";
}

supportingFiles.add(new SupportingFile(gradleBuildFile + ".mustache", "", gradleBuildFile));
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"));

Expand All @@ -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");
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group "{{groupId}}"
version "{{artifactVersion}}"

wrapper {
gradleVersion = '6.9'
gradleVersion = '7.3'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.caching=true
kotlin.code.style=official
ktor_version=2.3.12
kotlin_version=2.0.20
logback_version=1.4.14
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,33 @@ plugins {

dependencies {
{{#reactive}} val kotlinxCoroutinesVersion = "1.6.1"
{{/reactive}} compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}}
compile("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}}
compile("org.springframework.boot:spring-boot-starter-webflux")
compile("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
compile("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
compile("org.springdoc:springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui:1.6.8"){{/useSwaggerUI}}{{^useSwaggerUI}}
compile("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:1.6.8"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
compile("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
compile("org.webjars:swagger-ui:4.10.3")
compile("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
compile("io.swagger:swagger-annotations:1.6.6"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
compile("io.swagger.core.v3:swagger-annotations:2.2.0"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}
{{/reactive}} implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlin:kotlin-reflect"){{^reactive}}
implementation("org.springframework.boot:spring-boot-starter-web"){{/reactive}}{{#reactive}}
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-reactor:$kotlinxCoroutinesVersion"){{/reactive}}{{#springDocDocumentationProvider}}{{#useSwaggerUI}}
implementation("org.springdoc:springdoc-openapi-{{#reactive}}webflux-{{/reactive}}ui:1.6.8"){{/useSwaggerUI}}{{^useSwaggerUI}}
implementation("org.springdoc:springdoc-openapi-{{#reactive}}webflux{{/reactive}}{{^reactive}}webmvc{{/reactive}}-core:1.6.8"){{/useSwaggerUI}}{{/springDocDocumentationProvider}}{{#springFoxDocumentationProvider}}
implementation("io.springfox:springfox-swagger2:2.9.2"){{/springFoxDocumentationProvider}}{{#useSwaggerUI}}{{^springDocDocumentationProvider}}
implementation("org.webjars:swagger-ui:4.10.3")
implementation("org.webjars:webjars-locator-core"){{/springDocDocumentationProvider}}{{/useSwaggerUI}}{{^springFoxDocumentationProvider}}{{^springDocDocumentationProvider}}{{#swagger1AnnotationLibrary}}
implementation("io.swagger:swagger-annotations:1.6.6"){{/swagger1AnnotationLibrary}}{{#swagger2AnnotationLibrary}}
implementation("io.swagger.core.v3:swagger-annotations:2.2.0"){{/swagger2AnnotationLibrary}}{{/springDocDocumentationProvider}}{{/springFoxDocumentationProvider}}

compile("com.google.code.findbugs:jsr305:3.0.2")
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
compile("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
compile("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
{{#useBeanValidation}}
compile("javax.validation:validation-api"){{/useBeanValidation}}
compile("javax.annotation:javax.annotation-api:1.3.2")
testCompile("org.jetbrains.kotlin:kotlin-test-junit5")
testCompile("org.springframework.boot:spring-boot-starter-test") {
implementation("javax.validation:validation-api"){{/useBeanValidation}}
implementation("javax.annotation:javax.annotation-api:1.3.2")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(module = "junit")
}
{{#reactive}}
testCompile("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinxCoroutinesVersion")
{{/reactive}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group "org.openapitools"
version "1.0.0"

wrapper {
gradleVersion = '6.9'
gradleVersion = '7.3'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group "org.openapitools"
version "1.0.0"

wrapper {
gradleVersion = '6.9'
gradleVersion = '7.3'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/kotlin-server-modelMutable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.caching=true
kotlin.code.style=official
ktor_version=2.3.12
kotlin_version=2.0.20
logback_version=1.4.14
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading