Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ default:
before_script:
- source .gitlab/gitlab-utils.sh
- *container_info
- |
if [ -z "${S3_BUILD_CACHE_PREFIX+x}" ]; then
s3_cache_arch=$(uname -m)
s3_cache_os=$(uname -s | tr '[:upper:]' '[:lower:]')
if [[ "${CI_COMMIT_TAG:-}" =~ [^[:space:]] ]]; then
export S3_BUILD_CACHE_PREFIX="v1/release/${CI_PIPELINE_ID:?}/$s3_cache_arch/$s3_cache_os/"
else
export S3_BUILD_CACHE_PREFIX="v1/$s3_cache_arch/$s3_cache_os/"
Comment thread
sarahchen6 marked this conversation as resolved.
Resolved
fi
fi
# Akka token added to SSM from https://account.akka.io/token
- export ORG_GRADLE_PROJECT_akkaRepositoryToken=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-java.akka_repo_token --with-decryption --query "Parameter.Value" --out text)
- export ORG_GRADLE_PROJECT_mavenRepositoryProxy=$MAVEN_REPOSITORY_PROXY
Expand Down Expand Up @@ -575,6 +585,8 @@ validate_build:
variables:
CACHE_TYPE: "lib"
script:
# Rebuild independently of the cache used to produce the reference artifacts.
- export GRADLE_ARGS="$GRADLE_ARGS --no-build-cache --rerun-tasks"
# Preserve the `build` job artifacts before Gradle rebuilds and overwrites them under
# workspace/**/build/libs, so jardiff can compare the rebuilt jars against them.
- mkdir -p reference-artifacts
Expand All @@ -586,7 +598,6 @@ validate_build:
# Refresh them here as well so the candidate uses the same dependency resolution.
- if [ $CI_PIPELINE_SOURCE == "schedule" ] ; then ./gradlew resolveAndLockAll --write-locks $GRADLE_ARGS; fi
- ./gradlew --version
# This will run the shadowJar task and exercise the build cache, allowing to identify build-cache issues
# Keep both JAR sets for direct inspection when the comparison fails.
- |
if ! ./gradlew compareToReferenceJar -PjardiffReferenceDir="$CI_PROJECT_DIR/reference-artifacts" -PskipTests $GRADLE_ARGS; then
Expand Down
9 changes: 9 additions & 0 deletions dd-java-agent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ def traceShadowJar = tasks.register('traceShadowJar', ShadowJar) {
}
includeShadowJar(traceShadowJar, 'trace', includedJarFileTree)

[sharedShadowJar, traceShadowJar].each { shadowJarTask ->

@sarahchen6 sarahchen6 Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without this, Gradle can reuse a cached agent JAR with version stamps from an older commit (failing validate_build). This makes Gradle notice when those stamps change and rebuild the JAR.

shadowJarTask.configure {
// Track packaged bytes, including version files ignored by classpath normalization.
inputs.files(includedDependencies)
.withPropertyName('packagedDependencies')
.withPathSensitivity(PathSensitivity.NONE)
}
}

tasks.named("shadowJar", ShadowJar) {
// Include AgentPreCheck compiled with Java 6.
from sourceSets.main_java6.output
Expand Down
9 changes: 9 additions & 0 deletions docs/how_to_work_with_gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,15 @@ When Gradle builds fail or behave unexpectedly, several tools and techniques can
> [!TIP]
> In general following the [Gradle best practices](https://docs.gradle.org/current/userguide/best_practices.html) is safe bet to avoid isses.

### S3 Build Cache in GitLab CI

`S3_BUILD_CACHE_PREFIX` overrides the full prefix; Gradle appends the task cache key.
Defaults are `v1/<architecture>/<os>/` for non-tag builds (including master) and
`v1/release/<CI_PIPELINE_ID>/<architecture>/<os>/` for tags. Include the pipeline ID
in release overrides to preserve isolation.

`validate_build` compares build artifacts against an uncached rebuild.

### Forcing Fresh CI Task Execution

Set the GitLab CI variable `SKIP_BUILD_CACHE=true` when starting a pipeline.
Expand Down
11 changes: 6 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ plugins {

val isCI = providers.environmentVariable("CI")
val isGitLabCI = providers.environmentVariable("GITLAB_CI")
val isGitLabTag = providers.environmentVariable("CI_COMMIT_TAG")
val gitLabRefSlug = providers.environmentVariable("CI_COMMIT_REF_SLUG")
val skipBuildscan = providers.environmentVariable("SKIP_BUILDSCAN").map { it.toBoolean() }.orElse(false)

develocity {
Expand All @@ -58,12 +56,15 @@ if (isCI.isPresent) {
local {
directory = File(rootDir, "workspace/build-cache")
}
if (isGitLabCI.isPresent && !isGitLabTag.isPresent) {
if (isGitLabCI.isPresent) {
val cachePrefix = providers.environmentVariable("S3_BUILD_CACHE_PREFIX").orNull?.trim()?.trim('/')
require(!cachePrefix.isNullOrBlank()) {
"S3_BUILD_CACHE_PREFIX must be set to a non-empty path in GitLab CI"
}
remote<com.github.burrunan.s3cache.AwsS3BuildCache> {
region = providers.environmentVariable("S3_BUILD_CACHE_REGION").get()
bucket = providers.environmentVariable("S3_BUILD_CACHE_BUCKET").get()
prefix =
"trial/v1/${gitLabRefSlug.get()}/${System.getProperty("os.arch")}/"
prefix = "$cachePrefix/"
isPush = true
lookupDefaultAwsCredentials = true
isReducedRedundancy = false
Expand Down
Loading