Skip to content
jbaxPublic

About

A shared gradle build setup for java projects of any size, whether you're working on a single library, 100+ separate git repositories, or a few multi-module projects sitting side by side.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

Gradle reactor parent

This is a shared gradle build setup for java projects of any size, whether you're working on a single library, 100+ separate git repositories, or a few multi-module projects sitting side by side.

Everything runs in java through the gradle wrapper. Building, testing, checking module dependencies and signing releases should work right away with just the JDK installed.

What this build system does

1. It brings scattered repositories into one reactor

Supports focused views, parallel clones, and one atomic merge:

Repositories beside parent become one reactor then focused views parallel clones and one atomic merge

2. Enables profiles and binary dependencies:

Here upstream modules swap for pre-built jars and the same test run comes back through quickcheck

Upstream modules swap for pre-built jars and a quickcheck run returns in under a second

3. Independent clones without a mess.

Here we clone the worktree at an old tag, fix and test on JDK 21, tag and publish from the detached view, cherry-pick only the fix, then clean up the clone:

Backport flow in a worktree clone from a JDK 21 fix to the cleanup of the clone

All while the work on the main reactor goes on unaffected. You can work on many parallel views at the same time.

Summary

It should allow you to use gradle WELL and painlessly even if you don't know anything about it and doesn't care to learn (and re-learn every time you switch projects)

I have always hated on gradle because it can be HARD to get it doing what you want and every new project is a new "adventure" filled of script hell no one understands. Maven and declarative build configs are WAY easier - learn the recipe and repeat it everywhere. But maven can way too slow - especially if you have many large subprojects or modules. Reusing your configs also means some degree of copy-pasting which I find annoying to say the least.

I hope to have solved many of the issues of BOTH maven and gradle here and added a few extra batteries too.

When you have several java libraries or modules that depend on each other, you usually end up stuck between two not-so-great choices: cram everything into one giant git repository, or publish a new version of library A every time you want to test a change in library B.

This parent lets you skip both (hopefully). The idea here is that you can keep each project in its own folder, with its own git repository (if you want), and build all of them together in one gradle workspace:

  1. Build separate projects together

    • Put each project folder next to parent/ and gradle picks it up automatically, so one project can depend on another with project(":core")
    • gradle/libs.versions.toml: keeps all your library, plugin, and Java versions in one shared file
    • gradle/reactor.properties: keeps project info, test runner choice, and build options in one place
  2. Work on just a small slice of a big workspace

    • createView: when a workspace grows to dozens of projects, you can generate a smaller workspace that only loads one project and the projects it uses
    • viewClone: creates an isolated git copy of those projects on a temporary branch so you can edit and test safely, keep every project on the same branch, and merge everything back cleanly without leaving half of your repos merged and the other half stuck
    • viewAddModule and viewRetireModule: split out a brand-new module or retire an obsolete one inside a worktree clone, then promote or archive it atomically during viewMerge

    See Focused mini-reactor views and isolated git worktree clones.

  3. Tag releases, rebuild past versions, and target older java versions

    • isOss: mark open-source libraries with ext["isOss"] = true while keeping private projects separate
    • prepareRelease: run your configured pre-release checks, bump the semantic version, and create the release git tag without guessing missing settings
    • releaseManifest and viewFromTag: save the exact git tags used for a release so you can recreate and test that exact release later on
    • -PtargetJdk: compile and run tests for an older java version like java 21 with a single flag

    See Versioning, releases, backports, and publishing.

  4. Safe publishing with built-in signing

    • publish: makes sure your git folder has no uncommitted edits, runs any configured reactor.publish.tasks checks, and sits on the right release tag before uploading anything. For maven central, it signs your files in memory with PGP. For private maven repositories (nexus, artifactory, or self-hosted servers), it uploads older-java builds under separate names like text-jdk21.
    • ReactorSecrets: reads usernames, tokens, and signing keys from a file stored outside git
    • templates/github/publish.yml and templates/github/publish-backport.yml: ready-to-use github actions workflows for tagged releases and backports
  5. Packaging, opt-in code checks, fast profiles, and checked documentation

  6. Custom stuff I ported from old java code into gradle tasks

    • couplingUi: to inspect module dependencies in a browser - to help clear silly and unused dependencies, and to help keep module-info.java files tight. See Quality, static analysis, dependencies, and coupling audits
    • render-docs: a hopefully decent markdown template to help write guides like this one. If checks every markdown link, heading, and code snippet when building documentation. Since I'm dumb and I kept editing the rendered markdown instead of the template, render-docs --check ensures no drift and rescues direct edits to the rendered file back into the templates. See Writing live documentation with render-docs

How things fit together

There are really just three moving parts:

  • parent/: holds the gradle wrapper, shared build plugins, library versions, and settings. You open parent/ in your IDE or run ./gradlew from here
  • Your project folders like ../core/, ../app/, and ../reports/: sit right next to parent/ as plain folders or separate git repos, and talk to each other with project(":core")
  • Views and clones: smaller temporary gradle workspaces generated from parent/ when you only want to load a few projects, try something out on a git branch of every project in the view clone, or rebuild an old release tag

That's all you need to know for now, so let's get started.

Guides

This README covers setting up a workspace, configuring parent, creating two modules, and using it with a monorepo or an existing multi-project build. After going through it, check out the dedicated guides:

Quick start checklist

1. Files to edit after cloning parent/

File Required? What to change
gradle/reactor.properties Yes Set your reactor.name, reactor.group, reactor.base.package, reactor.target.jdk, reactor.test.framework (testng, junit, or none), vendor/developer/SCM metadata, and release tag format (reactor.release.tag.format). Or start by copying a profile from templates/reactor.properties.*.
gradle/libs.versions.toml Yes Set the build JDK (java) and add the third-party libraries, bundles, and plugins your projects use
gradle/reactor.local.properties Optional (gitignored) Machine-local overrides that should not be committed: reactor.views.root, reactor.secrets.file, reactor.extensions.dir, or a default reactor.profile. Both can also live outside the repository: a reactor.local.properties in any reactor.extensions.dir folder layers over this file, next to an optional profiles.local.properties (folders load in the order listed and conflicting values fail the build)
gradle/profiles.properties Optional Custom build profiles you can name to execute only the tasks you want (so you can run ./gradlew :<someproject>:runOnlyThisTestOrDieAfter_5_Seconds)
gradle/release.versions.toml Optional Define how you want your version numbers to look
gradle.properties Optional Adjust daemon memory (org.gradle.jvmargs) or parallel/cache flags.

2. What each subproject must look like

Drop each project folder next to parent/ (or under reactor.modules.dir).

my-workspace/
  parent/                            # a clone of this repo
  my-module/
    settings.gradle.kts              # required: rootProject.name = "my-module"
    build.gradle.kts                 # required: applies org.jbax.internal-conventions
    src/main/java/                   # your code  

Inside ../my-module/settings.gradle.kts you just need the project name - this is always a one-liner (I could not figure out how to make you NOT need this file, so here it is)

rootProject.name = "my-module"

And in ../my-module/build.gradle.kts you define your dependencies:

plugins { id("org.jbax.internal-conventions") } // the only thing that is required if there are no dependencies. 
ext["isOss"] = true // if you want to open-source your code, keep this line. Set to false/delete for commercial/private stuff. 

dependencies { 
	api(project(":core"))            // depends on another module managed by the parent
	implementation(libs.slf4j.api)   // comes from parent/gradle/libs.versions.toml - where ALL libraries and their versions are defined.
}

If your modules live in one git repository, or in an existing multi-project gradle build that already has its own settings.gradle.kts, see Using with a monorepo or multi-project builds.

Run ./gradlew checkReactorHealth from parent/ anytime to verify every sibling module is wired cleanly.

Setting up your projects from scratch

Starting a new multi-repo java workspace from zero takes four short steps.

Step 1: Create your workspace folder and clone parent

Put parent/ in a workspace folder next to the Java projects you want to build together:

my-workspace/
  parent/            # shared build plugins, versions, wrapper
  core/              # project 1 (plain folder or its own git repo)
  app/               # project 2 that uses :core
  reports/           # optional: an existing multi-project gradle build

Create the folder and clone parent into it:

mkdir my-workspace
cd my-workspace
git clone <url-to-this-repo> parent
cd parent

If you'd rather name the folder something else, like build-parent/, just set reactor.build.dir=build-parent in gradle/reactor.properties.

Step 2: Copy starter profiles and configure your project settings

parent/templates/ includes ready-to-copy starter files so you don't have to write gradle/reactor.properties from a blank page:

Copy the shared defaults plus either the private or public profile into parent/gradle/:

# For a private multi-repo workspace:
cp templates/reactor.properties.common gradle/reactor.common.properties
cp templates/reactor.properties.private gradle/reactor.properties

# Or for a single public open-source repository:
# cp templates/reactor.properties.common gradle/reactor.common.properties
# cp templates/reactor.properties.public gradle/reactor.properties

Gradle loads gradle/reactor.common.properties first and then applies gradle/reactor.properties on top. Now edit those files with your own name, maven group, base Java package, target JDK, test framework, and release settings:

# gradle/reactor.properties
reactor.name=acme-reactor

# gradle/reactor.common.properties
reactor.group=com.acme
reactor.base.package=com.acme
reactor.target.jdk=27

# testng -> adds TestNG and runs TestNG suites
# junit  -> adds JUnit 5 and runs JUnit Platform tests
# none   -> leaves test libraries and runners up to each module
reactor.test.framework=junit

# Release tagging and pre-release task checks used by prepareRelease
reactor.release.tag.format=v{version}
reactor.release.prepare.tasks=render-docs,test,javadoc
reactor.release.prepare.tasks.root=render-docs

Every option has comments and examples right inside gradle/reactor.properties. Put machine-local settings like your personal reactor.views.root folder or reactor.secrets.file path in gradle/reactor.local.properties so git ignores them, and put a reactor.local.properties (plus an optional profiles.local.properties) in a reactor.extensions.dir folder when you want them to live outside the repository entirely.

The main JDK version, currently java 27 under java, and every third-party library or plugin version live in gradle/libs.versions.toml. Individual modules just reference libs.<alias> from that catalog so you don't have version numbers scattered everywhere. Default version settings for internal modules live in gradle/release.versions.toml.

Step 3: Scaffold your first modules

Instead of copying boilerplate folders by hand, run initializeModule from parent/ to create an open-source library called core and a private app called app:

./gradlew initializeModule --mode=OSS --module=core
./gradlew initializeModule --mode=INTERNAL --module=app

Gradle prints where both projects were created:

initialized OSS module core at /path/to/my-workspace/core
initialized INTERNAL module app at /path/to/my-workspace/app

Here's what gets generated inside ../core/:

../core/
  .gitignore
  build.gradle.kts
  settings.gradle.kts
  src/
    main/
      java/
        module-info.java
        com/acme/core/.gitkeep
      resources/.gitkeep
    test/
      java/
        com/acme/core/.gitkeep

A few things to note here:

  • ../core/settings.gradle.kts only has rootProject.name = "core", which lets parent link it directly as a subproject
  • ../core/build.gradle.kts applies org.jbax.internal-conventions and sets ext["isOss"] = true because we passed --mode=OSS. ../app/build.gradle.kts leaves that out, so app stays private
  • Since we set reactor.test.framework=junit in Step 2, JUnit 5 is already wired up. If you pick testng, initializeModule also generates src/test/resources/testng.xml pointing to com.acme.core.*
  • Each module folder can be initialized as its own git repository (git -C ../core init) whenever you want independent commit history

If you want to create a module in a different folder instead of next to parent/, pass --target=/path/to/folder.

Step 4: Connect app to core, verify workspace health, and run tests

Let's add a simple class in ../core/src/main/java/com/acme/core/Greeter.java:

package com.acme.core;

public class Greeter {
	public static String hello(String name) {
		return "Hello, " + name + "!";
	}
}

Export its package in ../core/src/main/java/module-info.java:

open module com.acme.core {
	exports com.acme.core;
}

Now tell app to depend on core in ../app/build.gradle.kts:

plugins { id("org.jbax.internal-conventions") }

dependencies {
	api(project(":core"))
}

And declare the module requirement in ../app/src/main/java/module-info.java:

open module com.acme.app {
	requires com.acme.core;
}

From parent/, verify that gradle discovered both modules cleanly, check workspace health, and run your tests:

./gradlew projects
./gradlew checkReactorHealth
./gradlew test

You should see :core and :app linked up and passing the health check:

Reactor: linking core
Reactor: linking app
...
--- Reactor Health Check ---
[OK] [app]: Reactor module settings OK.
[OK] [core]: Reactor module settings OK.

To work in an IDE like intellij, just open parent/ as a gradle project and all your sibling projects will load together with the same Java version and library catalog.

If you use maven

If you're coming from maven, you're used to two familiar files: a parent pom that holds shared compiler settings, plugin versions, and <dependencyManagement>, and an aggregator pom.xml with <modules> that builds all your libraries together.

The catch with maven is that a multi-module <modules> reactor normally pushes you into a single giant git repository, or forces you to run mvn install on library A every time you want to test a change in library B. parent/ gives you the same shared build config and live multi-module build while letting every module stay in its own independent git repository with its own small settings.gradle.kts and build.gradle.kts.

Maven to parent quick reference

If you use this in maven Use this in parent
<parent> pom.xml with shared plugins and compiler config plugins { id("org.jbax.internal-conventions") } plus gradle/reactor.properties
Aggregator pom.xml with <modules> Drop project folders next to parent/; gradle discovers them automatically and links them via project(":core")
<dependencyManagement> / BOM gradle/libs.versions.toml shared version catalog (libs.<alias>)
Maven profiles (<profiles> / -Pprofile) Layered gradle/reactor.common.properties, gradle/reactor.properties, gradle/reactor.local.properties plus any reactor.extensions.dir folder, and -P<key>=<value> overrides
maven-enforcer-plugin Built-in --release target JDK checks, checkReactorHealth, auditBuildSystem, and clean-tree/tag publish checks
maven-shade-plugin shadeEmbed, shadeBundle, and postShadeJar in shading-conventions.gradle.kts
mvn install ./gradlew publishToMavenLocal (writes standard jars and pom files into ~/.m2/repository)
mvn deploy ./gradlew publish (with clean-tree check, tag check, and in-memory PGP signing)
mvn release:prepare ./gradlew prepareRelease (--patch, --minor, --major, --release-version, --release-dry-run, --push)
mvn -pl text -am test ./gradlew -Preactor.view=text test for one command, or createView / viewClone for a focused IDE workspace

Migrating existing maven modules one at a time

You don't need a big-bang rewrite to move off maven:

  1. Keep the exact same maven coordinates by setting reactor.group in gradle/reactor.properties to your existing maven <groupId>. Each module's folder name becomes its <artifactId> (or <artifactId>-jdk21 when building a Java 21 backport with -PtargetJdk=21), and its version comes from your git tag or version pattern.
  2. Convert one module at a time by adding a minimal settings.gradle.kts (rootProject.name = "core") and build.gradle.kts (plugins { id("org.jbax.internal-conventions") }) next to your existing src/main/java and src/test/java folders - gradle uses the exact same src/main and src/test directory layout as maven.
  3. Publish standard maven poms automatically. Every module gets gradle's maven-publish plugin wired up by publishing-conventions.gradle.kts, complete with <name>, <description>, <licenses>, <developers>, <scm>, and resolved dependencies. Inspect the generated pom file anytime with:
    ./gradlew :core:generatePomFileForMavenPublication
  4. Stay compatible with maven consumers by running ./gradlew :core:publishToMavenLocal so your remaining maven projects pick up core right from ~/.m2/repository. When you're ready to deploy, point reactor.publish.central.url at maven central or reactor.publish.backport.url at your private maven repository. Downstream maven builds depend on your published groupId:artifactId:version like any normal maven library and never need gradle installed.

Open-source vs. private modules

One line in a module's build.gradle.kts decides whether it's open-source or private:

  • Open-source module: add ext["isOss"] = true. It gets numbered versions like 1.0.14 or a git tag version like 1.2.0, can be part of public releases via releaseManifest, and can be exported cleanly without tests or git history via publicExport
  • Private / internal module: leave ext["isOss"] unset or false. It gets a date-based version like 2026.11.25 when internal-release = "AUTO" in gradle/release.versions.toml, and gradle won't let it slip into a public open-source release by mistake

You can flip a private module to open-source whenever you're ready by adding ext["isOss"] = true. See Versioning, releases, backports, and publishing for the full release and backport flow.

Using with a monorepo or multi-project builds

Pick the setup that matches how your modules are stored.

Option A: all modules in one git repository

When every module lives in one git repository, you do not need include(...) or composite builds. Put the parent files at the repository root, place the modules under modules/, and set reactor.modules.dir=modules in gradle/reactor.properties:

my-monorepo/               # one git repository
  settings.gradle.kts      # parent files at the root
  build.gradle.kts
  build-logic/
  gradle/                  # reactor.properties sets reactor.modules.dir=modules
  modules/
    core/                  # settings.gradle.kts + build.gradle.kts + src/
    app/                   # build.gradle.kts declares project(":core")

Every folder under modules/ is discovered automatically. ./gradlew projects lists :core and :app, -Preactor.view=app slices the reactor the same way as anywhere else, and initializeModule scaffolds new modules straight into modules/ because its default target is <reactor.modules.dir>/<module>.

The git tasks that assume one repository per module keep that assumption. Release manifests and worktree clones read git history from individual module folders, so a single-repository monorepo uses normal git branches and tags for those.

Option B: an existing multi-project gradle build

With reactor.nested.builds=true, which is the default, a sibling folder whose settings.gradle.kts calls include(...) or includeBuild(...) is attached as a gradle composite build. Gradle attaches that folder unchanged, so it still builds on its own:

my-workspace/
  parent/
  core/                    # flat module, discovered the usual way
  reports/
    settings.gradle.kts    # include(":reports-api", ":reports-cli")
    reports-api/
    reports-cli/

./gradlew projects from parent/ prints:

Reactor: linking nested build reports
Reactor: linking core

The subprojects inside reports/ pick up parent conventions only when they apply id("org.jbax.internal-conventions"), which needs one pluginManagement line in reports/settings.gradle.kts. Add the shared catalog plugin next to it when the nested build wants libs.<alias> from gradle/libs.versions.toml:

pluginManagement { includeBuild("../parent/build-logic") }
plugins { id("org.jbax.shared-catalogs") }

rootProject.name = "reports"
include(":reports-api", ":reports-cli")

That plugin also registers java toolchain downloads, so versions stay in the catalog and no settings file declares a toolchain resolver. Use ./gradlew buildNestedBuilds to build every nested build in one command, or pass -Preactor.nested.builds=false to leave them out of a run.

Keep subproject names inside a nested build distinct from the top-level module names, otherwise the IDE shows two projects with the same name.

Checking workspace health and saving a commit snapshot

After adding projects, moving folders around, or upgrading gradle, you can verify everything is wired up properly using the audit tasks in reactor-conventions.gradle.kts:

./gradlew checkReactorHealth
./gradlew auditBuildSystem

Sample output:

--- Build System Audit Result ---
Active Gradle Version: 9.9.3
[OK] 'libs' Catalog: Resolved (4 libraries)

[OK] All modules have healthy infrastructure links!
-----------------------------------

When your projects are separate git repositories and you want a snapshot file recording the current branch and commit hash of every repo, run:

./gradlew generateManifest

This writes a timestamped TOML file inside the folder configured by reactor.publish.manifest.dir, like parent/manifests/manifest-20261125-1430.toml.

Adjusting memory and upgrading gradle

By default, gradle runs with a 4 GB heap configured in gradle.properties. If you need more memory for a heavy build without editing checked-in files:

GRADLE_OPTS="-Dorg.gradle.jvmargs=-Xmx8g" ./gradlew build

NOTE: always pass -Dorg.gradle.jvmargs=... here. A plain -Xmx8g in GRADLE_OPTS only changes the tiny launcher process and won't resize the actual gradle daemon.

To upgrade gradle across parent/ and all generated views:

./gradlew wrapper --gradle-version latest --distribution-type bin
./gradlew :wrapper
./gradlew help --warning-mode all
./gradlew --stop

Next up: Fast builds, named profiles, and binary dependencies.

This page was generated from docs/templates/README.md using ./gradlew :render-docs.

About

A shared gradle build setup for java projects of any size, whether you're working on a single library, 100+ separate git repositories, or a few multi-module projects sitting side by side.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Packages

Contributors

Languages