From 8ad06a748aca1cb1b0ac08ea0e88186afdbd84bd Mon Sep 17 00:00:00 2001 From: Chris Dombroski Date: Thu, 21 Nov 2024 21:42:41 -0500 Subject: [PATCH] Extract model gen to submodule --- backend-model/build.gradle.kts | 67 +++++++++++++++++++ .../src/main/resources/openapi.yml | 0 backend/.gitignore | 13 ---- backend/build.gradle.kts | 36 +--------- settings.gradle.kts | 2 +- 5 files changed, 69 insertions(+), 49 deletions(-) create mode 100644 backend-model/build.gradle.kts rename {backend => backend-model}/src/main/resources/openapi.yml (100%) delete mode 100644 backend/.gitignore diff --git a/backend-model/build.gradle.kts b/backend-model/build.gradle.kts new file mode 100644 index 0000000..73b5b24 --- /dev/null +++ b/backend-model/build.gradle.kts @@ -0,0 +1,67 @@ +plugins { + java + id("io.spring.dependency-management") version "1.1.6" + id("org.openapi.generator") version "7.10.0" + idea +} + +group = "org.springframework.samples" + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +dependencyManagement { + imports { + mavenBom ("org.springframework.boot:spring-boot-dependencies:3.3.6") + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-validation") + implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0") +} + +tasks.withType { + dependsOn(tasks.openApiGenerate) +} + +java.sourceSets["main"].java { + srcDir(layout.buildDirectory.dir("generated/sources/openapi/src/main/java")) +} + +openApiGenerate { + inputSpec.set("${projectDir}/src/main/resources/openapi.yml") + outputDir.set(layout.buildDirectory.dir("generated/sources/openapi").map { it.asFile.absolutePath }) + generatorName.set("spring") + library.set("spring-boot") + modelNameSuffix.set("Dto") + apiPackage.set("org.springframework.samples.petclinic.rest.api") + modelPackage.set("org.springframework.samples.petclinic.rest.dto") + supportingFilesConstrainedTo.set(listOf("ApiUtil.java")) + globalProperties.set( + mapOf( + "apis" to "", + "models" to "" + ) + ) + configOptions.set( + mutableMapOf( + "verbose" to "true", + "interfaceOnly" to "true", + "performBeanValidation" to "true", + "dateLibrary" to "java8", + "useSpringBoot3" to "true", + "openApiNullable" to "false", + "serializationLibrary" to "jackson", + "documentationProvider" to "springdoc", + ) + ) +} \ No newline at end of file diff --git a/backend/src/main/resources/openapi.yml b/backend-model/src/main/resources/openapi.yml similarity index 100% rename from backend/src/main/resources/openapi.yml rename to backend-model/src/main/resources/openapi.yml diff --git a/backend/.gitignore b/backend/.gitignore deleted file mode 100644 index ad07b8f..0000000 --- a/backend/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -target/* -.settings/* -.classpath -.project -.idea -*.iml -/target - -generated/ - -# Easier branch switching -springboot-petclinic-client/ -springboot-petclinic-server/ diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 8dffcf0..cd734db 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -2,7 +2,6 @@ plugins { java id("org.springframework.boot") version "3.3.6" id("io.spring.dependency-management") version "1.1.6" - id("org.openapi.generator") version "7.10.0" idea jacoco } @@ -30,7 +29,7 @@ dependencies { implementation("org.springframework.data:spring-data-jdbc-core:1.2.1.RELEASE") implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0") implementation("org.mapstruct:mapstruct:${project.property("mapstructVersion")}") -// implementation("org.openapitools:jackson-databind-nullable:0.2.6") + implementation(project(":backend-model")) annotationProcessor("org.mapstruct:mapstruct-processor:${project.property("mapstructVersion")}") runtimeOnly("org.hsqldb:hsqldb") testImplementation("org.springframework.boot:spring-boot-starter-test") @@ -39,34 +38,6 @@ dependencies { testRuntimeOnly("org.junit.platform:junit-platform-launcher") } -openApiGenerate { - inputSpec.set("${projectDir}/src/main/resources/openapi.yml") - generatorName.set("spring") - library.set("spring-boot") - modelNameSuffix.set("Dto") - apiPackage.set("org.springframework.samples.petclinic.rest.api") - modelPackage.set("org.springframework.samples.petclinic.rest.dto") - supportingFilesConstrainedTo.set(listOf("ApiUtil.java")) - globalProperties.set( - mapOf( - "apis" to "", - "models" to "" - ) - ) - configOptions.set( - mutableMapOf( - "verbose" to "true", - "interfaceOnly" to "true", - "performBeanValidation" to "true", - "dateLibrary" to "java8", - "useSpringBoot3" to "true", - "openApiNullable" to "false", - "serializationLibrary" to "jackson", - "documentationProvider" to "springdoc", - ) - ) -} - tasks.jacocoTestReport { dependsOn(tasks.test) // tests are required to run before generating the report classDirectories.setFrom( @@ -106,12 +77,7 @@ tasks.withType { } } -java.sourceSets["main"].java { - srcDir(layout.buildDirectory.dir("generate-resources/main/src/main/java")) -} - tasks.withType { - dependsOn(tasks.openApiGenerate) options.compilerArgs = listOf( "-Amapstruct.suppressGeneratorTimestamp=true", "-Amapstruct.suppressGeneratorVersionInfoComment=true", diff --git a/settings.gradle.kts b/settings.gradle.kts index b672baa..b730a22 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,5 +4,5 @@ * The settings file is used to specify which projects to include in your build. * For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.7/userguide/multi_project_builds.html in the Gradle documentation. */ -include("backend") rootProject.name = "petclinic" +include("backend", "backend-model")