Ajout de tâches Gradle

This commit is contained in:
FyloZ 2021-02-10 20:41:17 -05:00
parent 7599479e59
commit 3c4eb78916
2 changed files with 57 additions and 24 deletions

1
.gitignore vendored
View File

@ -10,5 +10,6 @@ build/
logs/
workdir/
dokka/
dist/
/src/main/resources/angular/static/*

View File

@ -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<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
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)