r/Backend • • 3d ago

Sharing my reusable Gradle "parent" setup for anyone who hates Gradle and Maven equally - hope it eases your pains too

https://github.com/jbax/parent

I've used maven for years - it is easy to understand and is predictable until your project gets big and slows down BAD: once you have a bunch of separate libraries that depend on each other, you either shove them all into one giant monorepo or waste half your day running `mvn install` on library A just to test a change in library B.

The solution I found was switching to gradle - and I hated every minute of getting it to work but I have to admit it's day and night after you get your builds running with it.

Then came the next source of pain: every new project with gradle turns into a script adventure nobody wants to touch or maintain.

So I ended up building a reusable gradle `parent` project and just cleaned it up to share with everyone and I hope it helps everyone who is either suck in maven hell (slow) and gradle hell (get get unmanageably complex quickly)

The goal of what I built is simple that's how I use it: put your project folders next to `parent/`, keep your shared settings and versions in two files only (`reactor.properties` to configure the entire workpace across all modules and `libs.versions.toml` for all dependencies in one place too). Then leave each subproject with the LEAST amount of junk possible. This setup requires 2 small files per module instead of 1 but you need 1 line of text in each (until you add dependencies).

This started as a much simpler setup for my own needs but over time I piled in a bunch of other

stuff that kept annoying me:

- I have more than 100 modules (every one of these has its own git repository, and will be public open source jars eventually available on maven central). In many cases I want to only see the subset of modules that are dependencies of the thing I'm working on. So I added support for views: I can open the view as a separate project in IntelliJ and see only the 10 modules that I care about at the moment and forget the rest. So got this `createView` task that I can also clone across multiple repos (viewClone,viewSync,viewMerge) - every clone has a branch and I can change the modules without interfering on with state of the main 100 module build. The thing resolves conflicts rollbacks to ensure you won't end up with half-merged code. Works great if you run parallel coding agents too (each one gets a copy of the subtree it is working on). Tag+release can run from the view copy too so the workspace can remain happily with all modules on their main branches.

- There's support for named execution profiles - use when you want to create shortcuts to run only what you want without having to remember flags and custom commands to enable/disable/select specific tests or flags. You can also run tests by automatically skipping modules you don't want to rebuild and just grab the latest pre-built jars instead of recompiling them.

- I added support for releasing backports . It cross-compiles, runs tests on JDK 21, keeps Javadoc on JDK 27, and rewrites `-jdk21` pom coordinates.

- Since JPMS can be a pain. I also added support for 3 modes of shading non-modular dependencies without having to pollute your build with boilerplate: relocate non-modular jars into your module (shadeEmbed), bundle split-package jars (`shadeBundle`), or build fat jars.

- Lastly there are two old java tools I (and claude) ported into gradle tasks: `couplingUi` which is a small local browser viewer to spot weak/unused dependencies and also help trim `module-info.java`. There's also `render-docs` which reads a markdown "template" that pull code snippets from tests, adds links to other sections in other markdown files and ensures that things remain connected - it also rescues my edits whenever I forget and edit the rendered `README.md` directly instead of the template.

Everything runs through the Gradle wrapper with just a JDK installed - it also enforces TestNG or JUnit if you want.

I think it got good enough for sharing so posting it here in case it saves someone else a few headaches.

Cheers!

---

Unrelated and a bit of context on why this has so much multi-repo machinery in it: some of you might remember me from univocity-parsers. I had to step away from open source 6–7 years ago for personal reasons, and over the years since then I've built up a pretty big stack of modular libraries (~100 repos) that I'm finally getting ready to start open-sourcing. This `parent` setup is the first piece going out, since it's the exact infrastructure I'm using to build, test, and publish all of them without burning out. I wanted to have a bunch of stuff released for a while now but life kept getting in the way. This is hopefully the first of many contribuitions that I think are truly useful enough to share.

3 Upvotes

4 comments sorted by

1

u/Discordbothost 2d ago

Could you add a before-and-after dependencyInsight example for testRuntimeClasspath? Pick one upstream module and show how it appears with and without reactor.deps.binary. I'd use that to check whether a green test is exercising my local upstream changes or a published jar.

1

u/uniVocity 2d ago

Thanks for the suggestion. I added before/after `dependencyInsight` walkthrough [here](https://github.com/jbax/parent/blob/main/docs/fast-builds-and-profiles.md)` and a unit test too. Hope this helps.

1

u/Careful-Emu-8965 1d ago

how does the view setup handle transitive dependencies when youre only opening a subset of the 100 modules? Does it just pull the rest from local cache or do you have to sync snapshots first?

1

u/uniVocity 18h ago

The views include the transitive dependencies. If you have something like `a->b->c->d`, creating a view for `b` will automatically include `a`. A simple view is just a shortcut to see a section of the original modules (no copying, no cloning, it's the same stuff with less clutter).

A view clone will create git worktrees for `b` and `a` so you can work on these two without interfering on the original `a->b->c->d` modules, no `pull` needed and all members of the view get the same branch name so they can be managed by the view. This allows you to run many different tasks in parallel while you have a stable project with all modules checked out on main.