Skip to content

Share build logic through convention plugins and enable the configuration cache - #17

Merged
lhotari merged 1 commit into
mainfrom
gradle-build-logic
Sep 23, 2026
Merged

lhotari merged 1 commit into
mainfrom
gradle-build-logic

Conversation

@lhotari

@lhotari lhotari commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Gradle build refactoring following Gradle best practices. Based on #16 (CI improvements); review only the top commit.

What changes

  • build-logic/ included build (as in the Apache Pulsar build, kept small) with four precompiled convention plugins:
    • jonoffcpu.java-conventions: Corretto 25 toolchain, --release from jonoffcpu.javaRelease (default 21; the agent sets 17; it also drives the published org.gradle.jvm.version), UTF-8, Javadoc options, sources/javadoc JARs, disabled JUnit test, and check → every FixtureExec + :spotlessCheck (by path).
    • jonoffcpu.publish-conventions: the shared Maven Central/POM setup; modules set jonoffcpuPublication.displayName/description, and the converter overrides the license.
    • jonoffcpu.shaded-jar-conventions: the embeddedRuntime configuration, verifyDependencyDigests, the shaded JAR and its publication; modules add relocations and contents.
    • jonoffcpu.protobuf-conventions: the lite codec from docs/schema.
  • Typed tasks with declared inputs replace ad-hoc doLast blocks that called build-script functions: VerifyDependencyDigests, VerifyJarContents, VerifyNativeLibraries, GenerateNativeChecksums, VerifyAgentJar, and FixtureExec, which replaces the root script's STARTED/PASSED logging. The host C library is detected in a ValueSource, so /proc/self/maps (different on every run) is no configuration input.
  • Version catalog gradle/libs.versions.toml holds every library and plugin version. Repositories are declared once in settings, with FAIL_ON_PROJECT_REPOS.
  • No cross-project configuration: the root subprojects {} block is removed, the root directory is read via isolated.rootProject, and :spotlessCheck is depended on by path.
  • gradle.properties: org.gradle.configuration-cache=true, org.gradle.configureondemand=true and org.gradle.parallel=true, next to org.gradle.caching=true from Speed up CI and make its builds visible #16.
  • Spotless pinned to LF line endings. Its default reads git attributes through JGit, whose file-system probes made the configuration cache miss on every run ("an input to unknown location has changed"). Only gradlew.bat is CRLF, and Spotless doesn't format it.
  • Docs: AGENTS.md's build rules (catalog, convention plugins, configuration-cache rules) and the README's build notes and repository layout.

Verification

  • Configuration cache: before, the check graph stored with 22 problems; now it stores with none and a second run prints Reusing configuration cache. The same holds for publishToMavenLocal and a dry run of publishAndReleaseToMavenCentral -PsignAllPublications=true.
  • Configure-on-demand: :jonoffcpu-jfr-converter:check configures only :, build-logic and :jonoffcpu-jfr-converter.
  • Build cache: after clean, compileJava, generateProto, javadoc and the correlator's shadowJar are FROM-CACHE.
  • Checks: spotlessCheck :jonoffcpu-agent:check :jonoffcpu-correlator:check :jonoffcpu-jfr-converter:check -PnativeArchitectures=x86_64 -PnativeLibcs=all passes; all 19 fixture tasks run, including the native ones.
  • Artifacts compared with Speed up CI and make its builds visible #16's build (publishToMavenLocal, x86-64 glibc+musl): identical JAR entry lists, POMs and Gradle module metadata. The only difference is the order of the shaded JARs' manifest attributes, hence their size and hashes. Published JVM versions are unchanged: agent 17, correlator and converter 21.
  • The CI package job's command (-PprebuiltNative=true -PnativeArchitectures=all -PnativeLibcs=all) plans no Docker builds, as before.

Not verified locally

  • Actual signing and upload in the release workflow, which needs the release secrets. The release graph stores and reuses under the configuration cache without problems; if in doubt, the release step can add --no-configuration-cache.
  • arm64, which is left to CI.

@lhotari
lhotari added this pull request to stack #18 September 23, 2026 21:52
Base automatically changed from ci-improvements to main September 23, 2026 22:02
…tion cache

The three module build scripts repeated the toolchain, the Javadoc
options, the POM, the publication, the embedded-dependency digest check,
the shading setup and the fixture task wiring, and their task actions
called helper functions of the build script itself, which kept the
configuration cache from working (22 problems for the check tasks).

- build-logic/ is an included build with four precompiled convention
  plugins: jonoffcpu.java-conventions (Corretto 25 toolchain, --release
  from `jonoffcpu.javaRelease`, which also sets the published JVM
  version, UTF-8, Javadoc, fixtures), publish-conventions (the POM and
  Maven Central setup, license overridable), shaded-jar-conventions (the
  embeddedRuntime configuration, its digest check, the shaded JAR and its
  publication) and protobuf-conventions (the lite codec from
  docs/schema). They bring the third-party plugins as dependencies, so
  every module loads them from one class loader.
- The task logic is in typed task classes with declared inputs:
  VerifyDependencyDigests, VerifyJarContents, VerifyNativeLibraries,
  GenerateNativeChecksums, VerifyAgentJar, and FixtureExec, which
  reports each fixture class as the root build script did. The host C
  library is read by a value source, so /proc/self/maps, which differs
  on every run, is not a configuration input.
- Every library and plugin version is in gradle/libs.versions.toml.
  Repositories are declared once in the settings, and project
  repositories are refused.
- No project configures another: the root subprojects block is gone,
  the root directory is read through `isolated.rootProject`, and each
  module's check depends on :spotlessCheck by path.
- gradle.properties turns on the configuration cache, configure-on-
  demand and parallel execution, next to the build cache. Spotless now
  pins LF line endings: its default reads git attributes with JGit, whose
  file system probes invalidated the configuration cache on every run.

The check tasks of all three modules now store a configuration cache
entry without problems and reuse it on the next run. Configuring
:jonoffcpu-jfr-converter:check configures only the root and that project.
After a clean, compilation, the generated protobuf code, the Javadoc and
the correlator's shaded JAR come from the build cache. The published
artifacts are the same as before: the same JAR entries, POMs and Gradle
module metadata, with only the order of the shaded JARs' manifest
attributes changed; the agent still declares JVM 17 and the other
modules JVM 21.
@lhotari
lhotari merged commit c0e2263 into main Sep 23, 2026
10 checks passed
@lhotari
lhotari deleted the gradle-build-logic branch September 24, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant