Gradle Conventions

April 21, 2026 · View on GitHub

AutoValue in build files

See general-patterns.md for the AutoValue usage pattern. auto-value-annotations is provided globally by otel.java-conventions. Only add the annotation processor if the module uses AutoValue in production code:

dependencies {
  annotationProcessor("com.google.auto.value:auto-value")        // production
  testAnnotationProcessor("com.google.auto.value:auto-value")    // tests only
}

Convention plugins

Every module applies a base set of convention plugins from buildSrc/src/main/kotlin/.

PluginPurposeWho applies it
otel.java-conventionsBase Java toolchain, Checkstyle, Spotless, Error Prone, test configAll modules
otel.publish-conventionsMaven publishing, POM generationPublished (non-internal) modules
otel.animalsniffer-conventionsAndroid API level compatibility checkingModules targeting Android
otel.jmh-conventionsJMH benchmark supportModules with benchmarks
otel.japicmp-conventionsAPI diff generation against latest releasePublished modules (applied by otel.publish-conventions)
otel.protobuf-conventionsProtobuf code generationProtobuf modules only

A typical published module:

plugins {
  id("otel.java-conventions")
  id("otel.publish-conventions")
}

A testing-internal module (shared test utilities, not published):

plugins {
  id("otel.java-conventions")
  // no otel.publish-conventions
}

Dependency resolution

All external dependency versions are managed by :dependencyManagement (a BOM). Do not specify versions directly in build.gradle.kts — add new entries to the BOM if a version needs to be pinned.

otel.java-conventions configures failOnVersionConflict() and preferProjectModules() globally. Do not override these without a strong reason.

Module naming

Every module must declare its Java module name:

otelJava.moduleName.set("io.opentelemetry.sdk.metrics")

When the archive name cannot be derived correctly from the project name, set it explicitly:

base.archivesName.set("opentelemetry-api")

settings.gradle.kts ordering

New include(...) entries must be in alphabetical order within their surrounding group. The file is large — find the right lexicographic position before inserting.

Shared test utilities and test suites

See testing-patterns.md for shared test utility patterns and test suite registration.