See More

# Temporal Java Samples Scaffolding Guide (macOS) Follow these steps in a fresh directory to recreate a Gradle multi-module project like `temporalio-samples-java`. Commands assume the default macOS Terminal (zsh) and Homebrew-installed tooling. 1. **Prepare prerequisites** - Install Temportal CLI and Java (`brew install temporal gradle openjdk@17`) if you have not already. - Ensure the desired JDK is on the PATH: ```bash /usr/libexec/java_home -V # verify installed versions export PATH="/opt/homebrew/opt/openjdk@17/bin:$PATH" ``` 2. **Create the root directory** ```bash mkdir temporalio-samples-java cd temporalio-samples-java ``` 3. **Initialize Gradle** ```bash gradle init --type basic ./gradlew wrapper --gradle-version 8.7 ``` This seeds `settings.gradle`, `build.gradle`, and the Gradle wrapper. 4. **Declare subprojects** Edit `settings.gradle` so it lists every module you need: ```groovy rootProject.name = "temporalio-samples-java" include("core", "springboot", "springboot-basic", "docker") ``` 5. **Create module folders** ```bash for module in core springboot springboot-basic docker; do mkdir -p "$module/src/main/java" "$module/src/test/java" done ``` 6. **Author the root build** Populate `build.gradle` with the shared configuration (Temporal SDK version, Java plugins, repositories). ```groovy plugins { id("java") } group = "io.temporal.samples" version = "1.0.0-SNAPSHOT" subprojects { apply(plugin = "java") java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } repositories { mavenCentral() } dependencies { testImplementation("org.junit.jupiter:junit-jupiter:5.10.2") } tasks.test { useJUnitPlatform() } } ``` 7. **Add module-specific build files** - `core/build.gradle`: ```groovy dependencies { implementation("io.temporal:temporal-sdk:1.24.0") } ``` - `springboot/build.gradle` & `springboot-basic/build.gradle`: apply Spring Boot plugin and add Web + Temporal dependencies. ```groovy plugins { id("org.springframework.boot") version "3.2.5" id("io.spring.dependency-management") version "1.1.4" } dependencies { implementation("io.temporal:temporal-spring-boot-starter-alpha:1.24.0") implementation("org.springframework.boot:spring-boot-starter-web") testImplementation("org.springframework.boot:spring-boot-starter-test") } ``` 8. **Add source packages** Inside each module, create packages such as `io.temporal.samples.hello`, and add placeholder workflow/activity classes plus matching tests under `src/test/java`. 9. **Check formatting and run the build** ```bash ./gradlew spotlessApply # optional, once Spotless is configured ./gradlew build ``` 10. **Run samples** - Core workflow driver: `./gradlew :core:run --args='HelloActivity'`. - Spring Boot app: `./gradlew :springboot:bootRun`. With this scaffold in place you can begin porting or authoring workflows, activities, and Spring endpoints following the sample modules already organized under `io.temporal.samples`.