144 lines
4.4 KiB
Plaintext
144 lines
4.4 KiB
Plaintext
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
|
|
|
|
plugins {
|
|
java
|
|
id("org.springframework.boot") version "3.4.4"
|
|
id("io.spring.dependency-management") version "1.1.7"
|
|
id("org.openapi.generator") version "7.12.0"
|
|
}
|
|
|
|
group = "com.alttd"
|
|
version = "0.0.1-SNAPSHOT"
|
|
|
|
java {
|
|
toolchain {
|
|
languageVersion = JavaLanguageVersion.of(21)
|
|
}
|
|
}
|
|
|
|
configurations {
|
|
compileOnly {
|
|
extendsFrom(configurations.annotationProcessor.get())
|
|
}
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
|
compileOnly("org.projectlombok:lombok")
|
|
runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
|
|
annotationProcessor("org.projectlombok:lombok")
|
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
|
}
|
|
|
|
tasks.withType<Test> {
|
|
useJUnitPlatform()
|
|
}
|
|
|
|
// Generate Java API using OpenAPI Generator (Spring)
|
|
tasks.register<GenerateTask>("generateJavaApi") {
|
|
generatorName.set("spring")
|
|
inputSpec.set("$projectDir/open_api/api.yml")
|
|
val myBuildDir = layout.buildDirectory.get().asFile.absolutePath
|
|
outputDir.set("$myBuildDir/generated-sources/java")
|
|
apiPackage.set("com.alttd.api")
|
|
modelPackage.set("com.alttd.model")
|
|
configOptions.set(mapOf("interfaceOnly" to "true"))
|
|
}
|
|
|
|
// Make java compiling wait until after the API is generated
|
|
tasks.named("compileJava") {
|
|
dependsOn("generateJavaApi")
|
|
}
|
|
|
|
// Generate Angular API client using OpenAPI Generator (TypeScript-Angular)
|
|
tasks.register<GenerateTask>("generateFrontendApi") {
|
|
generatorName.set("typescript-angular")
|
|
inputSpec.set("$projectDir/open_api/api.yml")
|
|
outputDir.set("$projectDir/frontend/src/app/api")
|
|
configOptions.set(
|
|
mapOf(
|
|
"npmName" to "generated-api",
|
|
"supportsES6" to "true"
|
|
)
|
|
)
|
|
}
|
|
|
|
// Task to install npm dependencies in the frontend folder
|
|
tasks.register<Exec>("npmInstall") {
|
|
workingDir = file("$projectDir/frontend")
|
|
commandLine("npm.cmd", "install")
|
|
// commandLine("npm", "install")
|
|
}
|
|
|
|
tasks.named("jar") {
|
|
dependsOn("copyFrontend")
|
|
}
|
|
|
|
tasks.named("resolveMainClassName") {
|
|
dependsOn("copyFrontend") // Declare `copyFrontend` as a dependency
|
|
}
|
|
|
|
// Task to build the Angular frontend; depends on npmInstall and generateFrontendApi
|
|
tasks.register<Exec>("ngBuild") {
|
|
dependsOn("npmInstall", "generateFrontendApi")
|
|
workingDir = file("$projectDir/frontend")
|
|
// commandLine("npm", "run", "build")
|
|
commandLine("npm.cmd", "run", "build")
|
|
}
|
|
|
|
// Task to copy built frontend into "static" folder for Spring Boot
|
|
tasks.register<Copy>("copyFrontend") {
|
|
|
|
val myBuildDir = layout.buildDirectory.get().asFile.absolutePath
|
|
|
|
dependsOn("ngBuild") // Make sure frontend build runs first
|
|
from("$projectDir/frontend/dist") // Source directory for Angular build
|
|
into("$myBuildDir/resources/main/static") // Destination in Spring Boot's static folder
|
|
|
|
// Optional: Explicitly mark inputs and outputs for cache optimization
|
|
inputs.dir("$projectDir/frontend/dist")
|
|
outputs.dir("$myBuildDir/resources/main/static")
|
|
}
|
|
|
|
tasks.named("compileTestJava") {
|
|
dependsOn("copyFrontend") // Ensure `copyFrontend` runs before `compileTestJava`
|
|
}
|
|
|
|
// Ensure that the frontend is built and copied before bootJar
|
|
tasks.named("bootJar") {
|
|
dependsOn("copyFrontend") // Make bootJar depend on frontend build
|
|
}
|
|
|
|
//tasks.register("checkNpm") {
|
|
// doLast {
|
|
// // Print PATH for debugging
|
|
// val gradlePath = System.getenv("PATH")
|
|
// // Add location of npm to the PATH
|
|
// val nodePath = "C:\\Program Files\\nodejs"
|
|
// val updatedPath = "$gradlePath;$nodePath"
|
|
//
|
|
// // Check if npm is accessible
|
|
// try {
|
|
// val processBuilder = ProcessBuilder("npm", "-v")
|
|
// processBuilder.environment()["PATH"] = updatedPath // Explicitly set PATH
|
|
// val npmVersion = ProcessBuilder("npm", "-v")
|
|
// .redirectErrorStream(true) // Redirect error output to standard output
|
|
// .start()
|
|
// .inputStream
|
|
// .bufferedReader()
|
|
// .readText()
|
|
// .trim()
|
|
//
|
|
// println("npm version: $npmVersion")
|
|
// } catch (e: Exception) {
|
|
// println("Error: npm not found or not accessible. Make sure npm is added to your PATH.")
|
|
// e.printStackTrace()
|
|
// }
|
|
// }
|
|
//}
|