Java for Scala developers - practical guide if you want to write Java again.
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 |
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.gradleusingincludestatements (not inbuild.gradle) - The root
build.gradlecontains shared configuration viaallprojectsandsubprojectsblocks - Each submodule has its own
build.gradlefor language-specific plugins and dependencies - The
blogmodule is included for consistency but uses Jekyll for the actual build
Visit the blog at: https://sps23.github.io/java-for-scala-devs
- JDK 21
- Gradle 8.4+ (wrapper included)
./gradlew build./gradlew :java21:build
./gradlew :scala2:build
./gradlew :scala3:build
./gradlew :kotlin:build./gradlew testThis 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 |
To check if all code is properly formatted:
./gradlew spotlessCheckTo automatically format all code:
./gradlew spotlessApply./gradlew :java21:spotlessApply
./gradlew :scala2:spotlessApply
./gradlew :scala3:spotlessApply
./gradlew :kotlin:spotlessApplyNote: The build task automatically includes spotlessCheck, so the build will fail if code is not properly formatted.
To run the Jekyll blog locally:
cd blog
bundle install
bundle exec jekyll serveThen visit http://localhost:4000/java-for-scala-devs in your browser.
This project uses GitHub Actions for continuous integration. The workflow is triggered on:
- Push to
mainbranch - Pull requests to
mainbranch
To deploy the Jekyll blog to GitHub Pages, you need to enable GitHub Pages in repository settings (one-time setup):
- Go to Settings → Pages in the repository
- Under Build and deployment, set Source to GitHub Actions
- Save the settings
Once enabled, the workflow will automatically build and deploy the blog on push to main.
To enforce that all builds pass before merging PRs, configure branch protection rules:
- Go to Settings → Branches in the repository
- Click Add branch protection rule (or edit the existing rule for
main) - Set Branch name pattern to
main - Check Require status checks to pass before merging
- Search and select the following required status checks:
build-gradlebuild-jekyll
- Optionally check Require branches to be up to date before merging
- Click Save changes
This project is open source and available under the MIT License.