Skip to content

Commit

Permalink
[ANCHOR-533] Add Gradle tasks to start servers and run docker compose…
Browse files Browse the repository at this point in the history
… up (#1206)

### Description

Add Gradle tasks to start servers and run docker compose up

### Context

Improve developer experience

### Testing

- `./gradlew test`

### Documentation

Added instructions to how to contribute document.
  • Loading branch information
lijamie98 authored Nov 22, 2023
1 parent b4c8061 commit e45277e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 18 deletions.
51 changes: 33 additions & 18 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,33 @@ plugins {
jacoco
}

tasks {
register<Copy>("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<Copy>("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")
Expand All @@ -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") {
Expand Down Expand Up @@ -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**")
Expand Down Expand Up @@ -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()) }
6 changes: 6 additions & 0 deletions docs/01 - Contributing/A - Development Environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions service-runner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JavaExec>("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<JavaExec>("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")
}

0 comments on commit e45277e

Please sign in to comment.