Skip to content

Commit

Permalink
Update Gradle Build Cache config to permit read-only access
Browse files Browse the repository at this point in the history
- Always configure build cache, even if the credentials aren't present.
- When on CI, enable pushing to remove build cache, but disable local cache (to force CI to update the remote cache).
- Always set the credentials. Even if they're missing, then Gradle should permit read-only access.

This will improve build performance for all users.
  • Loading branch information
adam-enko committed Sep 10, 2024
1 parent bf0165e commit 5ceaa64
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ pluginManagement {

rootProject.name = "ktor"

val CACHE_USER = System.getenv("GRADLE_CACHE_USER")
val gradleBuildCacheUser = System.getenv("GRADLE_CACHE_USER")?.ifBlank { null }
val gradleBuildCachePassword = System.getenv("GRADLE_CACHE_PASSWORD")?.ifBlank { null }

if (CACHE_USER != null) {
val CACHE_PASSWORD = System.getenv("GRADLE_CACHE_PASSWORD")
buildCache {
remote(HttpBuildCache::class) {
isPush = true
setUrl("https://ktor-gradle-cache.teamcity.com/cache/")
credentials {
username = CACHE_USER
password = CACHE_PASSWORD
}
val isCi = !System.getenv("TEAMCITY_VERSION").isNullOrBlank() || !System.getenv("CI").isNullOrBlank()

buildCache {
local {
// Disable local cache when on CI, to make sure CI updates the remote cache.
isEnabled = !isCi
}
remote<HttpBuildCache> {
setUrl("https://ktor-gradle-cache.teamcity.com/cache/")
// Only push when credentials are present, otherwise, permit read-only access
isPush = gradleBuildCacheUser != null && gradleBuildCachePassword != null
credentials {
username = gradleBuildCacheUser
password = gradleBuildCachePassword
}
}
}
Expand Down

0 comments on commit 5ceaa64

Please sign in to comment.