Gradle Multi-Project

jbundle automatically detects and handles Gradle multi-project builds with multiple application subprojects.

How It Works

When jbundle detects settings.gradle.kts (or .gradle), it:

  1. Parses included subprojects

  2. Scans each for the application plugin

  3. Extracts mainClass, mainModule, and addModules configuration

  4. Offers selection or builds all with --all

Detection

jbundle looks for these patterns in build.gradle.kts:

plugins {
    id("application")
}

application {
    mainClass.set("com.example.Main")
}

And module configuration:

Single Subproject

Interactive Selection

When multiple application subprojects exist:

CLI Flag

Skip the prompt with --gradle-project:

Configuration File

Set default in jbundle.toml:

All Subprojects

Build every application subproject with --all:

Each binary is placed in {output}/{subproject-name}:

Module Handling

Automatic Detection

jbundle combines:

  1. jdeps analysis — Scans JAR for required modules

  2. Gradle config — Extracts addModules.add(...) from build files

Both are merged and deduplicated for the jlink runtime.

Manual Override

Bypass automatic detection with --modules:

Or in configuration:

Reusing Existing Runtime

If Gradle already built a jlink image, skip the jlink step:

Common locations jbundle checks:

  • {subproject}/build/jlink/

  • {subproject}/build/image/

  • {subproject}/build/jpackage/images/app-image/

Build Process

For subprojects, jbundle runs:

  1. :{subproject}:shadowJar (preferred, produces fat JAR)

  2. Falls back to :{subproject}:build if shadowJar unavailable

Then looks for JAR in:

  • {subproject}/build/libs/*-all.jar

  • {subproject}/build/libs/*-uber.jar

  • {subproject}/build/libs/*.jar

Configuration Reference

New options for multi-project builds:

CLI Flags

Flag
Description

--gradle-project <NAME>

Build specific subproject

--all

Build all application subprojects

--modules <LIST>

Manual module list (comma-separated)

--jlink-runtime <PATH>

Reuse existing jlink runtime

jbundle.toml

Examples

Simple Multi-Project

With Custom Modules

Troubleshooting

"No application subproject found"

Check that subprojects have the application plugin applied:

"Subproject 'x' not found"

Verify the subproject name matches what's in settings.gradle.kts:

Module errors at runtime

If the app fails with java.lang.module errors, modules are missing. Use --modules to add them:

shadowJar not available

If your project doesn't use Shadow plugin, ensure the regular build produces a fat JAR with all dependencies bundled.

Last updated

Was this helpful?