Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use environment variables to configure Gradle init scripts
System properties cannot be reliably read from init scripts in certain
versions of Gradle. This is not the case for environment variables.
  • Loading branch information
erichaagdev committed Nov 5, 2024
commit 5fd0927e475359a4eca54db1cd9050b1598274b7
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,18 @@ validate_build_config() {
}

execute_build() {
local args
args=(--build-cache --init-script "${INIT_SCRIPTS_DIR}/configure-remote-build-caching.gradle")
if [ -n "${remote_build_cache_url}" ]; then
args+=("-Ddevelocity.build-validation.remoteBuildCacheUrl=${remote_build_cache_url}")
fi
info "Running build:"
print_gradle_command

# shellcheck disable=SC2206 # we want tasks to expand with word splitting in this case
args+=(clean ${tasks})
# shellcheck disable=SC2086 # we want tasks to expand with word splitting in this case
invoke_gradle 1 \
--build-cache \
--init-script "${INIT_SCRIPTS_DIR}/configure-remote-build-caching.gradle" \
clean ${tasks}
}

info "Running build:"
print_gradle_command() {
info "./gradlew --build-cache -Dscan.tag.${EXP_SCAN_TAG} -Dscan.value.runId=${RUN_ID} -Dpts.enabled=false clean ${tasks}$(print_extra_args)"

invoke_gradle 1 "${args[@]}"
}

# Overrides summary.sh#print_experiment_specific_summary_info
Expand Down
59 changes: 36 additions & 23 deletions components/scripts/lib/gradle.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env bash

invoke_gradle() {
local run_num args
args=()
local run_num
run_num=$1
shift

Expand All @@ -12,35 +11,45 @@ invoke_gradle() {
cd "${project_dir}" > /dev/null 2>&1 || die "ERROR: Subdirectory ${project_dir} (set with --project-dir) does not exist in ${project_name}" "${INVALID_INPUT}"
fi

args+=(
--init-script "${INIT_SCRIPTS_DIR}/develocity-injection.gradle"
--init-script "${INIT_SCRIPTS_DIR}/configure-build-validation.gradle"
-Ddevelocity.injection.init-script-name=develocity-injection.gradle
-Ddevelocity.injection-enabled=true
envs+=(
DEVELOCITY_INJECTION_INIT_SCRIPT_NAME=develocity-injection.gradle
DEVELOCITY_INJECTION_ENABLED=true
)

if [ "$enable_ge" == "on" ]; then
args+=(
-Dgradle.plugin-repository.url=https://plugins.gradle.org/m2
-Ddevelocity.plugin.version="3.14.1"
-Ddevelocity.ccud.plugin.version="2.0.2"
envs+=(
GRADLE_PLUGIN_REPOSITORY_URL=https://plugins.gradle.org/m2
DEVELOCITY_PLUGIN_VERSION="3.14.1"
DEVELOCITY_CCUD_PLUGIN_VERSION="2.0.2"
)
fi

if [ -n "${ge_server}" ]; then
args+=(
-Ddevelocity.build-validation.url="${ge_server}"
-Ddevelocity.build-validation.allow-untrusted-server=false
envs+=(
DEVELOCITY_BUILD_VALIDATION_URL="${ge_server}"
DEVELOCITY_BUILD_VALIDATION_ALLOW_UNTRUSTED_SERVER=false
)
fi

if [ -n "${remote_build_cache_url}" ]; then
envs+=(
DEVELOCITY_BUILD_VALIDATION_REMOTEBUILDCACHEURL="${remote_build_cache_url}"
)
fi

args+=(
-Ddevelocity.build-validation.expDir="${EXP_DIR}"
-Ddevelocity.build-validation.expId="${EXP_SCAN_TAG}"
-Ddevelocity.build-validation.runId="${RUN_ID}"
-Ddevelocity.build-validation.runNum="${run_num}"
-Ddevelocity.build-validation.scriptsVersion="${SCRIPT_VERSION}"
-Ddevelocity.capture-file-fingerprints=true
envs+=(
DEVELOCITY_BUILD_VALIDATION_EXPDIR="${EXP_DIR}"
DEVELOCITY_BUILD_VALIDATION_EXPID="${EXP_SCAN_TAG}"
DEVELOCITY_BUILD_VALIDATION_RUNID="${RUN_ID}"
DEVELOCITY_BUILD_VALIDATION_RUNNUM="${run_num}"
DEVELOCITY_BUILD_VALIDATION_SCRIPTSVERSION="${SCRIPT_VERSION}"
DEVELOCITY_CAPTURE_FILE_FINGERPRINTS=true
)

local args
args=(
--init-script "${INIT_SCRIPTS_DIR}/develocity-injection.gradle"
--init-script "${INIT_SCRIPTS_DIR}/configure-build-validation.gradle"
-Dpts.enabled=false
)

Expand All @@ -57,9 +66,13 @@ invoke_gradle() {
rm -f "${EXP_DIR}/errors.txt"

debug "Current directory: $(pwd)"
debug ./gradlew "${args[@]}"
# shellcheck disable=SC2145
debug export "${envs[@]}"';' ./gradlew "${args[@]}"

if ./gradlew "${args[@]}"; then
# The parenthesis below will intentionally create a subshell. This causes the
# environment variables to only be exported for the child process and not leak
# to the rest of the script.
if (export "${envs[@]}"; ./gradlew "${args[@]}"); then
build_outcomes+=("SUCCESSFUL")
else
build_outcomes+=("FAILED")
Expand Down