From 3c4eb78916ffd60f264545b5203fdd431e2097d7 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Wed, 10 Feb 2021 20:41:17 -0500 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20t=C3=A2ches=20Gradle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + build.gradle.kts | 80 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 4858c3a..ec22b8e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,6 @@ build/ logs/ workdir/ dokka/ +dist/ /src/main/resources/angular/static/* diff --git a/build.gradle.kts b/build.gradle.kts index ea716f2..e7f6d14 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,4 @@ group = "dev.fyloz.trial.colorrecipesexplorer" -version = "1.3.1" -description = "Color Recipes Explorer" plugins { id("java") @@ -14,7 +12,6 @@ plugins { } repositories { - jcenter() mavenCentral() } @@ -47,7 +44,6 @@ dependencies { testImplementation("org.springframework.boot:spring-boot-test-autoconfigure:2.3.4.RELEASE") testImplementation("org.jetbrains.kotlin:kotlin-test:1.4.10") testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.4.10") -// testImplementation("io.mockk:mockk:1.10.2") runtimeOnly("com.h2database:h2:1.4.199") runtimeOnly("mysql:mysql-connector-java:8.0.22") @@ -69,26 +65,6 @@ sourceSets { } } -tasks.register("buildFrontend") { - exec { - if (System.getProperty("os.name").toLowerCase().contains("windows")) { - commandLine("cmd", "/c", "cd src/main/frontend && npm run-script build && xcopy dist\\color-recipes-explorer-frontend\\* ..\\resources\\angular\\static\\ /Y /E ") - } else { - commandLine("sh", "-c", "cd src/main/frontend && npm run-script build && cp -r dist/color-recipes-explorer-frontend/* ../resources/angular/static/") - } - } -} - -tasks.register("buildAngular") { - dependsOn("buildFrontend") - dependsOn(tasks.build) -} - -tasks.register("bootJarAngular") { - dependsOn("buildFrontend") - dependsOn(tasks.bootJar) -} - tasks.test { useJUnitPlatform() testLogging { @@ -107,3 +83,59 @@ tasks.withType { tasks.dokkaHtml { outputDirectory.set(rootDir.resolve("dokka")) } + +// Custom tasks + +tasks.register("buildBackend") { + val outputDirectory = "dist/backend" + println("Building Spring backend to ${projectDir.absolutePath}/$outputDirectory") + + dependsOn(tasks.bootJar) + + doLast { + // Creates the output directory if it does not exists. + val outputDirectoryFile = File("${projectDir.absolutePath}/$outputDirectory") + if (!outputDirectoryFile.exists() || !outputDirectoryFile.isDirectory) { + outputDirectoryFile.mkdirs() + } + + exec { + if (isUnixOs()) + commandLineUnix("cp build/libs/${project.name}.jar ${outputDirectoryFile.absolutePath}/${project.name}.jar") + else + commandLineWindows("xcopy build\\libs\\${project.name}.jar ${outputDirectoryFile.absolutePath}/${project.name}.jar") + } + } +} + +tasks.register("buildFrontend") { + val outputDirectory = "dist/frontend" + println("Building Angular frontend to ${projectDir.absolutePath}/$outputDirectory") + + // Creates the output directory if it does not exists. + val outputDirectoryFile = File("${projectDir.absolutePath}/$outputDirectory") + if (!outputDirectoryFile.exists() || !outputDirectoryFile.isDirectory) { + outputDirectoryFile.mkdirs() + } + + exec { + commandLineUniversal("cd src/main/frontend && npm install") + } + + exec { + commandLineUniversal("cd src/main/frontend && npm run-script build") + } + + exec { + if (isUnixOs()) + commandLineUnix("cp -r src/main/frontend/dist/color-recipes-explorer-frontend/* ${outputDirectoryFile.absolutePath}") + else + commandLineWindows("xcopy src\\main\\frontend\\dist\\color-recipes-explorer-frontend\\* ${outputDirectoryFile.absolutePath}") + } +} + +fun isUnixOs(): Boolean = "windows" !in System.getProperty("os.name").toLowerCase() +fun ExecSpec.commandLineUnix(command: String) = commandLine("sh", "-c", command) +fun ExecSpec.commandLineWindows(command: String) = commandLine("cmd", "/c", command) +fun ExecSpec.commandLineUniversal(command: String) = + if (isUnixOs()) commandLineUnix(command) else commandLineWindows(command)