mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
17.59.2025 2fc3f0400bddd07d0c152ac1dd6e6c599e3dd7c7
gradle...
4 files modified
132 ■■■■ changed files
.gitignore 1 ●●●● patch | view | raw | blame | history
borgbutler-server/build.gradle.kts 2 ●●● patch | view | raw | blame | history
borgbutler-webapp/build.gradle.kts 127 ●●●● patch | view | raw | blame | history
build.gradle.kts 2 ●●● patch | view | raw | blame | history
.gitignore
@@ -40,6 +40,7 @@
borgbutler-server/build
borgbutler-server/out
borgbutler-webapp/build
borgbutler-webapp/node
borgbutler-webapp/node_modules
borgbutler-docker/app/target
borgbutler-server-*
borgbutler-server/build.gradle.kts
@@ -61,7 +61,7 @@
}
tasks.named("distZip", Zip::class) {
    dependsOn(":borgbutler-webapp:packageWebApp")
    dependsOn(":borgbutler-webapp:webAppJar")
}
tasks.register("dist") {
borgbutler-webapp/build.gradle.kts
@@ -1,29 +1,100 @@
plugins {
    id("com.github.node-gradle.node") version "7.1.0"
    id("base") // Fügt die 'clean'-Task hinzu
}
node {
    // Configure the Node.js and npm versions
    version.set("23.1.0")
    // Version of npm to use
    // If specified, installs it in the npmWorkDir
    npmVersion.set("10.9.0")
    // npmVersion.set("") // If empty, the plugin will use the npm command bundled with Node.js
    download.set(true) // Downloads Node.js and npm instead of using a globally installed version
    // Set the directories for Node.js and npm installations using the modern Gradle API
    // Use a persistent directory outside the `build` folder
    workDir.set(layout.projectDirectory.dir("node/nodejs")) // Directory for Node.js installation
    npmWorkDir.set(layout.projectDirectory.dir("node/npm")) // Directory for npm installation
    // Explicitly set the Node.js binary path
    nodeProjectDir.set(file(layout.projectDirectory.dir(".").asFile.absolutePath))
}
tasks.named<Delete>("clean") {
    delete(
        file("node"),  // Delete download directory of node and npm.
        file("node_modules"),
        layout.buildDirectory
    )
}
tasks {
    // Configure the existing npmInstall task instead of registering a new one
    named<com.github.gradle.node.npm.task.NpmTask>("npmInstall") {
        group = "build"
        description = "Installs npm dependencies"
        args.set(listOf("install"))
        // Skip task if node_modules exists
        val nodeModulesDir = layout.projectDirectory.dir("node_modules")
        onlyIf {
            !nodeModulesDir.asFile.exists()
        }
        outputs.dir(project.layout.projectDirectory.dir("node_modules"))
    }
    register<com.github.gradle.node.npm.task.NpmTask>("npmBuild") {
        group = "build"
        description = "Builds the React project"
        args.set(listOf("run", "build"))
        dependsOn("npmInstall")
        inputs.files(fileTree("src")) // All source files as input
        outputs.dir("build") // React output directory as output
    }
    register<Copy>("copyReactBuild") {
        duplicatesStrategy = DuplicatesStrategy.EXCLUDE
        group = "build"
        description = "Copies built React files to the target directory"
        dependsOn("npmBuild") // Depends on the React build process
        from(file("build")) {
            // Exclude the target directory to prevent recursion
            exclude("resources/main/static/**")
        }
        from(file("src")) {
            include("index.html")
        }
        into(layout.buildDirectory.dir("resources/main/static")) // Target directory in the Gradle project
        // Skip task if target directory is up-to-date
        inputs.dir("build") // React build directory as input
        outputs.dir(layout.buildDirectory.dir("resources/main/static")) // Static resources directory as output
    }
    register<Jar>("webAppJar") {
        group = "build"
        description = "Package React build output as a JAR"
        archiveBaseName.set("borgbutler-webapp")
        archiveVersion.set(project.version.toString())
        destinationDirectory.set(layout.buildDirectory.dir("libs"))
        // Include files from react-build directory
        from(layout.buildDirectory.get()) {
            into("static") // Place files under /static in the JAR
            exclude("resources")
            exclude("libs")
            exclude("tmp")
        }
        // Include additional files (e.g., src/index.html)
        from(layout.projectDirectory.file("src/index.html")) {
            into("static") // Copy index.html to /static
        }
        dependsOn("copyReactBuild") // Ensure React build and copy are done first
    }
    // Include the React build in the Gradle build process
    named("build") {
        dependsOn("copyReactBuild") // Makes React build a part of the Gradle build
    }
}
description = "borgbutler-webapp"
tasks.register<Exec>("npmBuild") {
    workingDir = projectDir
    commandLine("sh", "-c", "npm run build")
}
tasks.register<Zip>("packageWebApp") {
    outputs.upToDateWhen { false } // Immer ausführen, damit nichts fehlt
    dependsOn("npmBuild")
    archiveBaseName.set("borgbutler-webapp")
    archiveExtension.set("jar")
    destinationDirectory.set(projectDir)
    from("build") {
        into("webapp") // Statische Ressourcen in webapp-Verzeichnis
    }
    doLast {
        val jarFile = archiveFile.get().asFile
        val targetDir = buildDir.resolve("libs")
        mkdir(targetDir)
        ant.invokeMethod("move", mapOf("file" to jarFile.absolutePath, "todir" to targetDir.absolutePath))
        println("*** packageWebApp finished.")
    }
}
build.gradle.kts
@@ -8,7 +8,7 @@
allprojects {
    group = "de.micromata.borgbutler"
    version = "0.8"
    version = "0.9"
}
subprojects {