Skip to content

[cleanup] PIP-463: Migrate build system from Maven to Gradle - #25398

Merged
merlimat merged 34 commits into
apache:masterfrom
merlimat:gradle
Mar 26, 2026
Merged

merlimat merged 34 commits into
apache:masterfrom
merlimat:gradle

Conversation

@merlimat

@merlimat merlimat commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Complete migration of Apache Pulsar's build system from Maven to Gradle, as proposed in PIP-463.

What this PR does:

  • Adds Gradle build scripts (build.gradle.kts, settings.gradle.kts, gradle/libs.versions.toml) for all modules
  • Converts all CI workflows from Maven to Gradle
  • Removes all Maven files (pom.xml, mvnw, .mvn/)
  • Adds enforced platform module (pulsar-dependencies) for consistent dependency versions
  • Adds binary license check and Trivy container scan to CI

Verified equivalence with Maven:

  • All CI test suites passing (unit, integration, system, shade tests on Java 17/21/24)
  • Server/shell distribution tarballs produce the same JARs
  • Shaded client JARs contain the same relocated classes
  • Docker images build and work correctly
  • NAR connector packages are identical

PoC PR with full CI green: merlimat#16

Test plan

  • All unit tests passing
  • All integration tests passing
  • All system tests passing (IO, Functions, Schema, Tiered Storage, Connectors)
  • Shade tests on Java 17/21/24
  • Binary license check passing
  • Docker images building correctly
  • Server distribution tarball verified against Maven output

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

- ShutdownUtil: detect Gradle test JVMs and use System.exit instead of
  Runtime.halt to allow proper Gradle test cleanup
- JavaInstanceDepsTest: adapt jar path detection for Gradle output layout
- PulsarClusterMetadataSetup: fix driver registration and error logging
- SchemaUtil: handle missing Gradle-specific schema exceptions
- PerformanceConsumer/Producer/Transaction: fix static counter leaks and
  timing issues in performance tests
- ConnectionTimeoutTest: fix flaky latch count
- OpenTelemetryServiceTest: force GC pressure for reliable metric test
- SaslAuthenticateTest: increase timeout for Gradle test environment
- PulsarBatchSourceE2ETest/PulsarSourceE2ETest: increase builtin test
  timeouts and fix E2E test configuration
- OffsetsCacheTest: adjust TTL for Gradle test timing
- BKCluster/PulsarMetadataBookieDriver: fix metadata driver initialization
- PulsarStandalone/Starter: minor compatibility adjustments
- SimpleTypedProducerConsumerTest: fix URL pattern for NAR directory
Complete Gradle build system for Apache Pulsar, replacing Maven for
all CI builds, tests, and distribution packaging.

Build system:
- Gradle build scripts for all modules with version catalog
- Enforced platform module (pulsar-dependencies) for consistent
  dependency version management across all modules
- Shadow JAR configurations for shaded client/admin/all JARs with
  proper relocation of asynchttpclient properties files
- NAR packaging for all IO connectors and tiered storage offloaders
- Server, shell, and IO distribution tarballs matching Maven output
- Integration and system test infrastructure with testcontainers

CI:
- GitHub Actions workflows converted from Maven to Gradle
- Develocity build scan integration
- Test grouping matching Maven surefire configuration
- Shade tests on Java 17/21/24
- System tests for IO connectors, functions, schema, tiered storage

Key technical decisions:
- Shade tests use files(shadowJar) for relocated classes with API
  modules as separate dependencies (not bundled in shadow JARs)
- Kinesis KPL shaded project forces protobuf 4.29.0 (relocated, no
  runtime conflict) since KPL requires protobuf 4.x
- jclouds-shaded bundles Guice 7.0.0 and Jakarta EE 10+ APIs
  (jakarta.annotation, jakarta.ws.rs, jakarta.inject) required by
  jclouds 2.6.0, isolated from Pulsar's javax-era versions
- Global NAR exclusions for platform modules and protobuf (provided
  by java-instance.jar at runtime)
- Conditional shade test project includes to avoid implicit parent
  project conflicts
Restore the check-binary-license.sh step that was in the Maven CI:
- In build-and-license-check: verify server distribution tarball
- In pulsar-test-latest-version-image: verify both server and shell
  distribution tarballs after Docker image build
Run Trivy vulnerability scan on the pulsar Docker image after build,
matching the Maven CI setup. Only runs on apache/pulsar master (not
on PRs or forks). Results are uploaded to GitHub Security tab.
Set add-job-summary: always on all Setup Gradle steps so the
Develocity build scan URL appears in every job's summary page,
not just on failures.
The upstream grpc bump (apache#25353) changed go.mod to require Go 1.24.0.
Update the Docker build to use golang:1.24-alpine matching Maven's
configuration.
@merlimat
merlimat requested a review from lhotari March 24, 2026 21:08
@merlimat merlimat changed the title PIP-463: Migrate build system from Maven to Gradle [cleanup] PIP-463: Migrate build system from Maven to Gradle Mar 24, 2026
@apache apache deleted a comment from github-actions Bot Mar 24, 2026
@github-actions github-actions Bot added doc-required Your PR changes impact docs and you will update later. and removed doc-label-missing labels Mar 24, 2026
@merlimat merlimat self-assigned this Mar 24, 2026
@merlimat merlimat added this to the 4.3.0 milestone Mar 24, 2026
The apache org requires third-party actions to use specific approved
commit SHAs, not version tags. Pin to the latest approved SHA from
apache/infrastructure-actions.
@lhotari

lhotari commented Mar 24, 2026

Copy link
Copy Markdown
Member

Please update the build instructions in README.md

@merlimat

Copy link
Copy Markdown
Contributor Author

Please update the build instructions in README.md

Yes, there are several followup cleanup tasks. One other is the bin/pulsar and other scripts that build the classpath. I'll address each separately.

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some initial commits, will continue with remaining

Comment thread .github/workflows/codeql.yaml Resolved
Comment thread .github/workflows/pulsar-ci-flaky.yaml Resolved
Comment thread .github/workflows/pulsar-ci.yaml Resolved
Comment thread distribution/shell/build.gradle.kts Resolved
Comment thread build.gradle.kts Resolved
Comment thread build.gradle.kts Resolved
Comment thread settings.gradle.kts Resolved
Comment thread pulsar-broker/build.gradle.kts Resolved
Comment thread pulsar-broker/build.gradle.kts Resolved
- Rename ci-maven-cache-update.yaml to ci-gradle-cache-update.yaml
- Pin gradle/actions/setup-gradle to SHA in codeql and flaky workflows
- Remove surefire-reports references from CI (Gradle uses build/reports)
- Upgrade Gradle wrapper to 9.4.1
- Move protobuf and develocity plugin versions to libs.versions.toml
- Filter Confluent Maven repo to io.confluent.* dependencies only
- Add comment about settings.gradle.kts plugin version sync
Rename project names in settings.gradle.kts so Gradle project names
match Maven artifactIds automatically, eliminating name-mapping hacks
in distribution builds:

- :pulsar-client -> :pulsar-client-original (dir: pulsar-client/)
- :pulsar-client-admin -> :pulsar-client-admin-original (dir: pulsar-client-admin/)
- :pulsar-functions:pulsar-functions-local-runner ->
  :pulsar-functions:pulsar-functions-local-runner-original (dir: pulsar-functions/localrun/)

All project() references updated across 37 build files.
Distribution name mappings for these three projects removed.

Also fix Confluent repo content filter regex to match both
"io.confluent" and "io.confluent.xxx" groups.
Create a Gradle java-platform module that publishes a BOM (Bill of
Materials) listing all Pulsar modules. Users import this to ensure
aligned versions across pulsar-client-api, pulsar-client, etc:

  implementation(enforcedPlatform("org.apache.pulsar:pulsar-bom:X.Y.Z"))

This replaces the Maven pulsar-bom POM that was generated by
src/gen-pulsar-bom.sh. The Gradle version uses project() references
so it's always in sync with the actual modules.
The Shadow plugin's filesMatching { filter { } } lambdas (used for
ahc-default.properties content relocation) capture Gradle script
references that can't be serialized by the configuration cache.
Add comments explaining this in the CI workflow and test runner script.
Replace rootProject.tasks.named() cross-project task references with
proper Gradle configuration-based artifact sharing. The root project
now exposes the filtered BK test jar as a consumable configuration,
and consumers depend on it via:
  project(path = ":", configuration = "filteredBkServerTestJar")

This makes the dependency visible to Gradle's task graph, caching,
and up-to-date checks.
Simplify IO and offloader distribution build scripts by extracting
the project list into a val and using forEach for NAR collection.

Note: The NAR plugin doesn't register proper Gradle variants for
artifact resolution, so configuration-based NAR collection
(artifactType = "nar") doesn't work yet. Keep the dependsOn + from()
pattern for now; this can be improved when the NAR plugin supports
variant-aware publishing.
The NAR plugin v0.1.2 registers .nar files as outgoing variants on
runtimeElements with artifactType = "nar". Distribution builds now
use Gradle's artifact view to resolve NAR files through proper
dependency resolution instead of direct path references with manual
dependsOn — Gradle handles task ordering, caching, and parallel
safety automatically.
Both :pulsar-io:pulsar-io-jdbc:postgres and
:pulsar-io:pulsar-io-debezium:postgres had Gradle project name
"postgres" with group "org.apache.pulsar", causing Gradle to
deduplicate them (resolving debezium:postgres → jdbc:postgres).

Fix by using qualified project names in settings.gradle.kts
(e.g., pulsar-io-jdbc-postgres, pulsar-io-debezium-postgres).
Same fix for "core" sub-modules which had the same clash.

Skip the archive name convention for projects whose name already
starts with the parent name (already qualified).
Let the gradle/actions/setup-gradle action handle Develocity
configuration via its injection mechanism. This ensures the access
key format is handled correctly regardless of whether the org-level
secret uses the server-prefixed format or bare token.

Remove the Develocity plugin from settings.gradle.kts and version
catalog, and enable injection with develocity-url in all workflows.
…OM entries conditional

Move pulsar-client-shaded, pulsar-client-admin-shaded, and
pulsar-client-all includes into the core modules section since
the BOM references them unconditionally.

Use findProject() for modules that are only available in full builds
(athenz, localrun-shaded, tiered-storage) to avoid build failures
when using -PcoreModules.

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments, will continue reviewing

Comment thread tests/integration/build.gradle.kts Resolved
Comment thread tests/integration/build.gradle.kts Resolved
Comment thread pulsar-client/build.gradle.kts Resolved
Comment thread pulsar-client-shaded/build.gradle.kts Resolved
Comment thread pulsar-common/build.gradle.kts Resolved
Comment thread pulsar-bom/build.gradle.kts Resolved
Comment thread settings.gradle.kts Resolved
- Replace findProperty() with providers.gradleProperty() in Docker
  build scripts for configuration cache compatibility
- Move hardcoded amazon-kinesis-client:3.1.2 to version catalog as
  amazon-kinesis-client-v3

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed all changes up to this point.
I guess that resolving the Netty native library shading is one of the most important things to address unless you already solved that.

Comment thread pulsar-io/kinesis/build.gradle.kts Resolved
…mpat, worker deps

- Replace all findProperty() with providers.gradleProperty() for
  configuration cache compatibility (items 21, 27)
- Relocate Netty native library filenames in all shaded JARs to
  avoid conflicts with unshaded Netty (item 23)
- Replace shell commands (hostname, date) with pure Java in
  pulsar-common version generation for Windows compatibility (item 25)
- Use dependency configurations instead of cross-project task
  references in pulsar-functions-worker tests (item 28)

@lhotari lhotari left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job!

We can solve maven publishing in a separate PR.
For example, comparing the local deployment of maven (mvn deploy -DaltDeploymentRepository=local-repo::file:./local-repo) with gradle's similar results.

publishing {
    repositories {
        maven {
            name = "localTest"  // <-- "LocalTest" becomes the repository name
            url = uri(layout.buildDirectory.dir("repo"))
        }
    }
}

and then ./gradlew publishAllPublicationsToLocalTestRepository

We'd also need to get rid of the conditionals in settings.gradle.kts since that causes problems in IDE and adds unnecessary complications. It shouldn't be needed in Gradle builds and is just a leftover from the maven build logic.

UPDATE: I added a comment in #25398 (comment) regarding the conditionals in settings.gradle.kts and why they are unnecessary since gradle provides a great way to achieve what is needed.

# Conflicts:
#	pulsar-client-messagecrypto-bc/pom.xml
@merlimat

Copy link
Copy Markdown
Contributor Author

Yes, this is just the starting point, that will allow development not to be interrupted. There are still remaining tasks needed and a lot of improvement opportunities.

@lhotari

lhotari commented Mar 26, 2026

Copy link
Copy Markdown
Member

Yes, this is just the starting point, that will allow development not to be interrupted. There are still remaining tasks needed and a lot of improvement opportunities.

Yes, let's get this merged and start iterating.

There's a great Gradle cache that would be useful for pull requests. With the solution only changed modules would required to be compiled, checked and so on. It's coming from an Apache Calcite maintainer and the action is already is already approved. https://github.com/marketplace/actions/gradle-cache#sample-integrations

@merlimat
merlimat merged commit 5b9fe44 into apache:master Mar 26, 2026
49 checks passed
@merlimat
merlimat deleted the gradle branch October 24, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required Your PR changes impact docs and you will update later. ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants