Skip to content

sps23/java-for-scala-devs

Repository files navigation

Java for Scala Developers

Java for Scala developers - practical guide if you want to write Java again.

Project Structure

This is a multi-module Gradle project with the following modules:

Module Description
blog Jekyll-based GitHub Pages blog
java21 Java 21 examples with preview features
scala2 Scala 2.13 examples
scala3 Scala 3 examples
kotlin Kotlin examples for comparison

Gradle Multi-Module Setup

This project uses a standard Gradle multi-module layout optimized for GitHub Pages:

java-for-scala-devs/
├── build.gradle       # Root build config (shared settings)
├── settings.gradle    # Declares all submodules
├── blog/              # Jekyll blog (GitHub Pages content)
│   └── build.gradle   # Minimal Gradle config (Jekyll handles build)
├── java21/
│   └── build.gradle   # Java-specific plugins and config
├── scala2/
│   └── build.gradle   # Scala 2.13-specific config
├── scala3/
│   └── build.gradle   # Scala 3-specific config
└── kotlin/
    └── build.gradle   # Kotlin-specific config

Key points:

  • Submodules are declared in settings.gradle using include statements (not in build.gradle)
  • The root build.gradle contains shared configuration via allprojects and subprojects blocks
  • Each submodule has its own build.gradle for language-specific plugins and dependencies
  • The blog module is included for consistency but uses Jekyll for the actual build

Blog

Visit the blog at: https://sps23.github.io/java-for-scala-devs

Building

Prerequisites

  • JDK 21
  • Gradle 8.4+ (wrapper included)

Build All Modules

./gradlew build

Build Specific Module

./gradlew :java21:build
./gradlew :scala2:build
./gradlew :scala3:build
./gradlew :kotlin:build

Run Tests

./gradlew test

Code Formatting

This project uses Spotless for code formatting with the following formatters:

Module Formatter Configuration
java21 Eclipse JDT .eclipse-formatter.xml
kotlin ktlint Default ktlint rules
scala2 Scalafmt .scalafmt.conf
scala3 Scalafmt .scalafmt.conf

Check Code Formatting

To check if all code is properly formatted:

./gradlew spotlessCheck

Apply Code Formatting

To automatically format all code:

./gradlew spotlessApply

Format Specific Module

./gradlew :java21:spotlessApply
./gradlew :scala2:spotlessApply
./gradlew :scala3:spotlessApply
./gradlew :kotlin:spotlessApply

Note: The build task automatically includes spotlessCheck, so the build will fail if code is not properly formatted.

Local Blog Development

To run the Jekyll blog locally:

cd blog
bundle install
bundle exec jekyll serve

Then visit http://localhost:4000/java-for-scala-devs in your browser.

CI/CD

This project uses GitHub Actions for continuous integration. The workflow is triggered on:

  • Push to main branch
  • Pull requests to main branch

GitHub Pages Setup

To deploy the Jekyll blog to GitHub Pages, you need to enable GitHub Pages in repository settings (one-time setup):

  1. Go to SettingsPages in the repository
  2. Under Build and deployment, set Source to GitHub Actions
  3. Save the settings

Once enabled, the workflow will automatically build and deploy the blog on push to main.

Required Status Checks

To enforce that all builds pass before merging PRs, configure branch protection rules:

  1. Go to SettingsBranches in the repository
  2. Click Add branch protection rule (or edit the existing rule for main)
  3. Set Branch name pattern to main
  4. Check Require status checks to pass before merging
  5. Search and select the following required status checks:
    • build-gradle
    • build-jekyll
  6. Optionally check Require branches to be up to date before merging
  7. Click Save changes

License

This project is open source and available under the MIT License.

About

Java for Scala developers - practical guide if you want to write Java again

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •