From 5706760bd00592918cf717fc5e64c054d8fea296 Mon Sep 17 00:00:00 2001 From: Jamie Li Date: Tue, 21 Nov 2023 08:23:32 +0800 Subject: [PATCH] Add Gradle tasks to start servers and run docker compose up --- build.gradle.kts | 51 ++++++++++++------- .../A - Development Environment.md | 6 +++ service-runner/build.gradle.kts | 20 ++++++++ 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b4818ed0c9..fdc9de923d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,20 +10,33 @@ plugins { jacoco } -tasks { - register("updateGitHook") { - from("scripts/pre-commit.sh") { rename { it.removeSuffix(".sh") } } - into(".git/hooks") - doLast { - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - project.exec { commandLine("chmod", "+x", ".git/hooks/pre-commit") } - } +// ******************************************************************************* +// Task registration and configuration +// ******************************************************************************* + +// The printVersionName task is used to print the version name of the project. This +// is useful for CI/CD pipelines to get the version string of the project. +tasks.register("printVersionName") { println(rootProject.version.toString()) } + +// The updateGitHook task is used to copy the pre-commit.sh file to the .git/hooks +// directory. This is part of the efforts to force the Java/Kotlin code to be formatted +// before committing the code. +tasks.register("updateGitHook") { + from("scripts/pre-commit.sh") { rename { it.removeSuffix(".sh") } } + into(".git/hooks") + doLast { + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + project.exec { commandLine("chmod", "+x", ".git/hooks/pre-commit") } } } - - "build" { dependsOn("updateGitHook") } } +tasks { build { dependsOn("updateGitHook") } } + +// ******************************************************************************* +// Common configurations +// ******************************************************************************* + subprojects { apply(plugin = "java") apply(plugin = "com.diffplug.spotless") @@ -47,10 +60,12 @@ subprojects { logger.warn("!!! WARNING !!!") logger.warn("=================") logger.warn( - " You are running Java version:[{}]. Spotless may not work well with JDK 17.", - javaVersion) + " You are running Java version:[{}]. Spotless may not work well with JDK 17.", + javaVersion + ) logger.warn( - " In IntelliJ, go to [File -> Build -> Execution, Build, Deployment -> Gradle] and check Gradle JVM") + " In IntelliJ, go to [File -> Build -> Execution, Build, Deployment -> Gradle] and check Gradle JVM" + ) } if (javaVersion < "11") { @@ -127,8 +142,9 @@ subprojects { test { useJUnitPlatform() systemProperty( - "junit.jupiter.testclass.order.default", - "org.junit.jupiter.api.ClassOrderer\$OrderAnnotation") + "junit.jupiter.testclass.order.default", + "org.junit.jupiter.api.ClassOrderer\$OrderAnnotation" + ) exclude("**/AnchorPlatformCustodyEnd2EndTest**") exclude("**/AnchorPlatformCustodyApiRpcEnd2EndTest**") @@ -167,10 +183,9 @@ allprojects { tasks.jar { manifest { attributes( - mapOf( - "Implementation-Title" to project.name, "Implementation-Version" to project.version)) + mapOf("Implementation-Title" to project.name, "Implementation-Version" to project.version) + ) } } } -tasks.register("printVersionName") { println(rootProject.version.toString()) } diff --git a/docs/01 - Contributing/A - Development Environment.md b/docs/01 - Contributing/A - Development Environment.md index 90763760bb..58013d1754 100644 --- a/docs/01 - Contributing/A - Development Environment.md +++ b/docs/01 - Contributing/A - Development Environment.md @@ -103,6 +103,12 @@ Run all tests: `./gradlew test` Run subproject tests: `./gradlew :[subproject]:test` +### Running `docker-compose` up for development +`./gradlew dockerComposeUp` + +### Starting all servers +`./gradlew startAllServers` + ## Set up the Git Hooks In order to have consistent code style, we use [Google Java Format](https://github.com/google/google-java-format) to diff --git a/service-runner/build.gradle.kts b/service-runner/build.gradle.kts index 8165f49e80..e7e4803e7b 100644 --- a/service-runner/build.gradle.kts +++ b/service-runner/build.gradle.kts @@ -39,3 +39,23 @@ tasks { } application { mainClass.set("org.stellar.anchor.platform.ServiceRunner") } + +/** + * Start all the servers based on the `default` test configuration. + */ +tasks.register("startAllServers") { + println("Starting all servers based on the `default` test configuration.") + group = "application" + classpath = sourceSets["main"].runtimeClasspath + mainClass.set("org.stellar.anchor.platform.run_profiles.RunAllServers") +} + +/** + * Run docker-compose up to start Postgres, Kafka, Zookeeper,etc. + */ +tasks.register("dockerComposeUp") { + println("Running docker-compose up to start Postgres, Kafka, Zookeeper,etc.") + group = "application" + classpath = sourceSets["main"].runtimeClasspath + mainClass.set("org.stellar.anchor.platform.run_profiles.RunDockerDevStack") +}