[improve][build] Adopt Gradle best practices: convention plugins, build-logic composite build, and unconditional module inclusion#25435
Open
lhotari wants to merge 14 commits intoapache:masterfrom
Conversation
…ld-logic composite build, and unconditional module inclusion Replace buildSrc with a build-logic composite build to avoid full build invalidation on build logic changes (gradle/gradle#6045). Extract the monolithic subprojects{}/allprojects{} blocks into convention plugins (pulsar.java-conventions, pulsar.code-quality-conventions, pulsar.test-certs-conventions, pulsar.nar-conventions) so each subproject explicitly opts in via its plugins{} block. Remove all conditional module inclusion from settings.gradle.kts (-PcoreModules, -Pdocker, -PintegrationTests, shade-test detection) so the project structure is deterministic and configuration cache friendly. Use tasks.withType<>().configureEach instead of eager withType<> blocks. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4562fdd to
7a17a67
Compare
merlimat
approved these changes
Mar 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Align the Gradle build with Gradle's documented best practices to improve build performance, maintainability, and configuration cache effectiveness. The main issues addressed:
subprojects{}/allprojects{}blocks — 260+ lines of shared config injected non-obviously, preventing Gradle's Isolated Projects optimizationbuildSrc— Gradle recommends composite builds overbuildSrcbecausebuildSrcchanges invalidate the entire build, causing all tasks to lose build cache entries (gradle/gradle#6045). Migrated tobuild-logic/composite build.settings.gradle.kts— dynamic project structure breaks configuration cache and IDE integrationtasks.withType<>without.configureEachcauses unnecessary configuration overheadgeneratePulsarVersiontask'sgitDirty/gitCommitIdinputs caused cascading rebuilds across the entire project on every file changeModifications
Convention plugins (build-logic composite build replacing buildSrc):
buildSrctobuild-logic/composite build per Gradle best practice, so build logic changes only invalidate projects that depend on the changed codepulsar.java-conventions,pulsar.code-quality-conventions,pulsar.test-certs-conventions,pulsar.nar-conventionsconvention pluginspulsar.shadow-conventionsandpulsar.client-shade-conventionsfrombuildSrctobuild-logicplugins { id("pulsar.java-conventions") }instead of inheriting fromsubprojects{}afterEvaluate+ reflection for license plugin configurationbuildSrc/andgradle/code-quality.gradle.ktsUnconditional module inclusion:
settings.gradle.kts(-PcoreModules,-Pdocker,-PintegrationTests, shade-test detection)assemble→dockerBuilddependency from Docker modulespulsar-bomproject references unconditionalConfiguration cache & build performance:
tasks.withType<>changed totasks.withType<>().configureEachfor lazy task configurationgitDirtyandgitCommitIdfromgeneratePulsarVersiontask inputs to prevent cascading rebuildspulsar-functions-runtime-allfat JAR from manualdependsOn(runtimeClasspath) + zipTree()to Shadow plugin for configuration-cache-compatible lazy resolutionshadow { addShadowVariantIntoJavaComponent.set(false) }in shadow conventionsaddShadowJarToAssembleLifecycleCI & documentation:
-PcoreModulesand-Pdockerflags from GitHub Actions workflows anddocker/build.shversion-catalog-updateandversionsplugins for dependency managementVerifying this change
This change is already covered by existing tests. Build verification:
./gradlew help— configuration phase succeeds./gradlew assemble— full build produces identical artifacts./gradlew assemble(second run) — "Reusing configuration cache", all tasks UP-TO-DATE./gradlew clean && ./gradlew assemble— allcompileJava/shadowJar/nartasks served FROM-CACHE./gradlew :pulsar-broker:test --dry-run— test task graph unchanged./gradlew :pulsar-io:pulsar-io-data-generator:nar --dry-run— NAR packaging worksDoes this pull request potentially affect one of the following parts:
Documentation
doc-not-needed