Skip to content

Commit

Permalink
Improve project structure (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
smidf authored Dec 26, 2023
2 parents 5e943c9 + 453a21e commit 5a4d19a
Show file tree
Hide file tree
Showing 46 changed files with 557 additions and 212 deletions.
26 changes: 9 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
buildscript {
repositories {
mavenCentral()
maven("https://nexus.eman.cz/repository/maven-public")
}

dependencies {
classpath(GradlePlugins.kotlin)
classpath(GradlePlugins.dokka)
classpath(Dependencies.GradlePlugins.swaggerCodeGen)
}
plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.dokka) apply false
}

allprojects {
repositories {
mavenCentral()
maven("https://nexus.eman.cz/repository/maven-public")
}

group = Artifact.groupId
group = "cz.eman.swagger"
}

tasks.create<Delete>("clean") {
delete(rootProject.buildDir)
}

tasks.getByName<Wrapper>("wrapper") {
gradleVersion = libs.versions.gradle.get()
distributionType = Wrapper.DistributionType.BIN
}
2 changes: 0 additions & 2 deletions buildSrc/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions buildSrc/build.gradle.kts

This file was deleted.

Empty file removed buildSrc/settings.gradle.kts
Empty file.
64 changes: 0 additions & 64 deletions buildSrc/src/main/kotlin/Dependencies.kt

This file was deleted.

3 changes: 0 additions & 3 deletions buildSrc/src/main/kotlin/GradleExt.kt

This file was deleted.

21 changes: 21 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[versions]
gradle = "8.4"

kotlin = "1.9.10"
dokka = "1.9.10"

openapi = "5.2.1"
jUnit = "5.7.2"
kotest = "4.6.1"


[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }


[libraries]
openapiGenerator = { group = "org.openapitools", name = "openapi-generator", version.ref = "openapi" }

jUnit = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "jUnit" }
kotest = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" }
File renamed without changes.
25 changes: 11 additions & 14 deletions lib/build.gradle.kts → plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java-gradle-plugin")
kotlin("jvm")
id("org.jetbrains.dokka")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.dokka)
id("maven-publish")
}

dependencies {
implementation(gradleApi())
implementation(Dependencies.Kotlin.kotlinStbLib)
implementation(Dependencies.Libs.openApiCodegen)
implementation(libs.openapiGenerator)

testImplementation(Dependencies.TestLibs.junit)
testImplementation(Dependencies.TestLibs.kotest)
testImplementation(libs.jUnit)
testImplementation(libs.kotest)
}

tasks.withType<KotlinCompile> {
Expand Down Expand Up @@ -43,11 +41,11 @@ val dokkaHtmlJar by tasks.creating(Jar::class) {
dependsOn(dokka)
}

val identifier = "swagger-codegen"
gradlePlugin {
plugins {
register("swagger-codegen-plugin") {
group = Artifact.groupId
id = Artifact.artifactId
id = identifier
implementationClass = "cz.eman.swagger.codegen.SwaggerCodeGenPlugin"
}
}
Expand All @@ -57,8 +55,7 @@ gradlePlugin {
publishing {
publications {
create<MavenPublication>("release") {
groupId = Artifact.groupId
artifactId = Artifact.artifactId
artifactId = identifier
from(components["java"])
artifact(sourcesJar)
artifact(dokkaHtmlJar)
Expand Down Expand Up @@ -101,9 +98,9 @@ publishing {
name = "Nexus"

credentials {
username = findPropertyOrNull("nexus.username")
password = findPropertyOrNull("nexus.password")
username = findProperty("nexus.username") as String?
password = findProperty("nexus.password") as String?
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ open class KotlinClientCodegen : org.openapitools.codegen.languages.KotlinClient
const val TYPE_ARRAY_LIST = "ArrayList"
}

enum class GenerateApiType constructor(val value: String) {
enum class GenerateApiType(val value: String) {
INFRASTRUCTURE("infrastructure"),
API("api")
}

enum class HeadersCommands constructor(val value: String) {
enum class HeadersCommands(val value: String) {
REMOVE_MINUS_WORD_FROM_PROPERTY(REMOVE_MINUS_TEXT_FROM_HEADER)
}

enum class EndpointsCommands constructor(val value: String) {
enum class EndpointsCommands(val value: String) {
INGORE_ENDPOINT_STARTING_SLASH(REMOVE_ENDPOINT_STARTING_SLASH)
}

Expand Down
8 changes: 8 additions & 0 deletions sample/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf
5 changes: 5 additions & 0 deletions sample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
106 changes: 5 additions & 101 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,105 +1,9 @@
import cz.eman.swagger.codegen.SwaggerCodeGenConfig
import cz.eman.swagger.codegen.SwaggerCodeGenTask
import cz.eman.swagger.codegen.SwaggerCodeGenTaskConfig
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java-library")
kotlin("jvm")
id("swagger-codegen")
id("kotlin-kapt")
}

dependencies {
// Kotlin
implementation(Dependencies.Kotlin.kotlinStbLib)
implementation(Dependencies.Retrofit.retrofit)
implementation(Dependencies.Tools.moshiKotlin) {
exclude(group = "org.jetbrains.kotlin")
}
implementation(Dependencies.Tools.moshiAdapters) {
exclude(group = "org.jetbrains.kotlin")
}
kapt(Dependencies.Tools.moshiCodegen)
}

/**
* Swagger/OpenApi generator config
*/
configure<SwaggerCodeGenConfig> {
sourcePath = "${project.projectDir.absolutePath}/openapi"
outputPath = "${buildDir.absolutePath}/openapi"
setLibrary("jvm-retrofit2")
setGeneratorName("cz.eman.swagger.codegen.generator.kotlin.KotlinClientCodegen")

setAdditionalProperties(
mutableMapOf(
"templateEngine" to "mustache",
"dateLibrary" to "string",
"enumPropertyNaming" to "original",
"modelNameSuffix" to "Dto",
"apiNameSuffix" to "",
"generateInfrastructure" to false,
"removeMinusTextInHeaderProperty" to true,
"ignoreEndpointStartingSlash" to true,
"serializationLibrary" to "moshi",
"moshiCodeGen" to true,
"removeOperationParams" to arrayOf(
"Accept-Language",
"ETag",
"X-Access-Token",
"X-Call-Chain-Id",
"X-Execution-TimeStamp",
"X-Release-Version"
)
)
)

configs = listOf(
SwaggerCodeGenTaskConfig(
inputFileName = "petstore.yaml",
outputFolderName = "petstore",
additionalProperties = mapOf(
"apiPackage" to "cz.eman.swagger.api.petstore",
"modelPackage" to "cz.eman.swagger.api.petstore.model",
"dateLibrary" to "java8"
)
),
SwaggerCodeGenTaskConfig(
inputFileName = "petstore-opt-def-arg-api.yaml",
outputFolderName = "petstore-def-and-opt-query",
additionalProperties = mapOf(
"apiPackage" to "cz.eman.swagger.api.petstore.defoptapi",
"modelPackage" to "cz.eman.swagger.api.petstore.defoptapi.model"
)
)
)
}

val generatedPetStoreSrcDir = File(buildDir, "openapi/petstore/src/main/kotlin")
val generatedPetStoreDefOptApiQuerySrcDir = File(buildDir, "openapi/petstore-def-and-opt-query/src/main/kotlin")

sourceSets {
getByName("main").java.srcDirs(
"src/main/kotlin",
generatedPetStoreSrcDir,
generatedPetStoreDefOptApiQuerySrcDir
)
getByName("test").java.srcDirs("src/test/kotlin")
}

val javaVersion = JavaVersion.VERSION_1_8
java {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = javaVersion.toString()
}
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.kapt) apply false
}

tasks.withType<SwaggerCodeGenTask> {
project.tasks.findByName("kaptGenerateStubsKotlin")?.dependsOn(this)
tasks.getByName<Wrapper>("wrapper") {
gradleVersion = libs.versions.gradle.get()
distributionType = Wrapper.DistributionType.BIN
}
27 changes: 27 additions & 0 deletions sample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[versions]
gradle = "8.4"

kotlin = "1.9.10"

moshi = "1.15.0"
retrofit = "2.9.0"


[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }


[libraries]
moshi-core = { group = "com.squareup.moshi", name = "moshi", version.ref = "moshi" }
moshi-adapters = { group = "com.squareup.moshi", name = "moshi-adapters", version.ref = "moshi" }
moshi-codegen = { group = "com.squareup.moshi", name = "moshi-kotlin-codegen", version.ref = "moshi" }

retrofit-core = { group = "com.squareup.retrofit2", name = "retrofit", version.ref = "retrofit" }
retrofit-converter-scalars = { group = "com.squareup.retrofit2", name = "converter-scalars", version.ref = "retrofit" }
retrofit-converter-moshi = { group = "com.squareup.retrofit2", name = "converter-moshi", version.ref = "retrofit" }


[bundles]
moshi = ["moshi-core", "moshi-adapters"]
retrofit = ["retrofit-core", "retrofit-converter-scalars", "retrofit-converter-moshi"]
Binary file added sample/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions sample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 5a4d19a

Please sign in to comment.