Update build scripts to integrate frontend with backend.

This commit is contained in:
Teriuihi 2025-04-18 22:24:55 +02:00
parent 5759d6c0dc
commit 25e8dc8e8e
2 changed files with 64 additions and 49 deletions

View File

@ -2,7 +2,6 @@ plugins {
java
id("org.springframework.boot") version "3.4.4"
id("io.spring.dependency-management") version "1.1.7"
// id("com.github.johnrengelman.shadow") version "8.1.1"
}
group = "com.alttd.altitudeweb"
@ -27,6 +26,7 @@ repositories {
dependencies {
implementation(project(":open_api"))
implementation(project(":database"))
implementation(project(":frontend"))
implementation("org.springframework.boot:spring-boot-starter-web")
annotationProcessor("org.projectlombok:lombok")
testImplementation("org.springframework.boot:spring-boot-starter-test")
@ -54,42 +54,13 @@ tasks.bootJar {
archiveClassifier.set("")
}
tasks.processResources {
dependsOn("includeFrontend")
}
//tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
// mergeServiceFiles()
// dependencies {
// include(dependency("com.mysql:mysql-connector-j"))
// }
//}
//tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
// manifest {
// attributes["Main-Class"] = "com.alttd.altitudeweb.AltitudeWebApplication"
// }
// archiveBaseName.set("altitudeweb")
// archiveClassifier.set("")
// mergeServiceFiles()
//
// // Include everything
// from(sourceSets.main.get().output)
//
// // Include all project dependencies
// configurations = listOf(project.configurations.runtimeClasspath.get())
//
// // Ensure MySQL is included (even though it should be part of runtimeClasspath already)
// dependencies {
// include(dependency("com.mysql:mysql-connector-j"))
// }
//
// // Enable zip64 mode for large JARs
// isZip64 = true
//}
//
//// Make the shadowJar task the default jar task
//tasks.named("jar") {
// enabled = false
//}
//
//tasks.named("assemble") {
// dependsOn("shadowJar")
//}
tasks.register<Copy>("includeFrontend") {
description = "Copy the built frontend to the Spring Boot static resources directory"
from("${project.rootDir}/frontend/dist")
into(layout.buildDirectory.dir("resources/main/static"))
doNotTrackState("Cannot reliably track state in the static directory")
}

View File

@ -1,14 +1,58 @@
tasks.register<Exec>("npmInstall") {
commandLine("npm.cmd", "install")
// commandLine("npm", "install")
import com.github.gradle.node.NodeExtension
import com.github.gradle.node.npm.task.NpmTask
plugins {
id("com.github.node-gradle.node") version "7.1.0"
id("base") // This adds the standard Gradle lifecycle tasks like "build"
}
tasks.register<Exec>("ngBuild") {
dependsOn("npmInstall", "generateFrontendApi")
// commandLine("npm", "run", "build")
commandLine("npm.cmd", "run", "build")
node {
download.set(true)
version.set("22.14.0")
npmVersion.set("10.9.2")
workDir.set(file("${project.projectDir}/node"))
npmWorkDir.set(file("${project.projectDir}/node"))
}
//dependencies {
// implementation(project(":backend"))
//}
// Clean the distribution directory
tasks.register<Delete>("cleanDist") {
description = "Clean the distribution directory"
delete("dist")
}
// Create a task that will run npm build
tasks.register("npmBuild") {
description = "Run 'npm run build'"
group = "build"
doLast {
// Use nodeCommand directly from the plugin
project.exec {
workingDir(project.projectDir)
// Use node's npm to ensure it works on all environments
val nodeDir = "${project.projectDir}/node"
val isWindows = System.getProperty("os.name").lowercase().contains("windows")
if (isWindows) {
val npmCmd = file(nodeDir).listFiles()?.find { it.name.startsWith("npm") && it.isDirectory }?.let {
"${it.absolutePath}/npm.cmd"
} ?: "$nodeDir/node_modules/npm/bin/npm.cmd"
commandLine(npmCmd, "run", "build")
} else {
val npmExecutable = file(nodeDir).listFiles()?.find { it.name.startsWith("npm") && it.isDirectory }?.let {
"${it.absolutePath}/npm"
} ?: "$nodeDir/node_modules/npm/bin/npm"
commandLine(npmExecutable, "run", "build")
}
}
}
dependsOn("npmInstall")
}
tasks.named("assemble") {
dependsOn("npmBuild")
}