Skip to content

Commit

Permalink
Refactor build-settings-logic to expose single plugin (#3834)
Browse files Browse the repository at this point in the history
* `dokkasettings` plugin should be applied to all projects in `settings.gradle.kts`
* content of `dokkasettings` is copied to `build-settings-logic` itself
* remove usage of user/password for build cache and use `develocity` extension
* move foojay toolchains there to share it
  • Loading branch information
whyoleg authored Sep 30, 2024
1 parent 407f053 commit 1ba220d
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 204 deletions.
3 changes: 1 addition & 2 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ dependencyResolutionManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("dokkasettings.build-cache")
id("dokkasettings")
}
1 change: 1 addition & 0 deletions build-settings-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ kotlin {
dependencies {
implementation(libs.gradlePlugin.gradle.develocity)
implementation(libs.gradlePlugin.gradle.customUserData)
implementation(libs.gradlePlugin.gradle.foojayToolchains)
}
108 changes: 102 additions & 6 deletions build-settings-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,109 @@ dependencyResolutionManagement {
}
}

// We have to make sure the build-cache config is consistent in the settings.gradle.kts
// files of all projects. The natural way to share logic is with a convention plugin,
// but we can't apply a convention plugin in build-settings-logic to itself, so we just copy it.
// We could publish build-settings-logic to a Maven repo? But this is quicker and easier.
// The following content should be kept in sync with the content of:
// `src/main/kotlin/dokkasettings.settings.gradle.kts`
// The only difference with the script above is explicitly specified versions

//region copy of src/main/kotlin/dokkasettings.settings.gradle.kts

// version should be kept in sync with `gradle/libs.versions.toml`
plugins {
id("com.gradle.develocity") version "3.17.6"
id("com.gradle.common-custom-user-data-gradle-plugin") version "2.0.2" apply false
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}

// We have to make sure the build-cache config is consistent in the settings.gradle.kts
// files of all projects. The natural way to share logic is with a convention plugin,
// but we can't apply a convention plugin in build-settings-logic to itself, unless we
// do it with a dumb hack:
apply(from = "src/main/kotlin/dokkasettings.build-cache.settings.gradle.kts")
// We could publish build-settings-logic to a Maven repo? But this is quicker and easier.
//region properties
val buildingOnTeamCity: Boolean = System.getenv("TEAMCITY_VERSION") != null
val buildingOnGitHub: Boolean = System.getenv("GITHUB_ACTION") != null
val buildingOnCi: Boolean = System.getenv("CI") != null || buildingOnTeamCity || buildingOnGitHub

fun dokkaProperty(name: String): Provider<String> =
providers.gradleProperty("org.jetbrains.dokka.$name")

fun <T : Any> dokkaProperty(name: String, convert: (String) -> T): Provider<T> =
dokkaProperty(name).map(convert)
//endregion

//region Gradle Build Scan
// NOTE: build scan properties are documented in CONTRIBUTING.md
val buildScanEnabled: Provider<Boolean> =
dokkaProperty("build.scan.enabled", String::toBoolean)
.orElse(buildingOnCi)

val BUILD_SCAN_USERNAME_DEFAULT = "<default>"

/** Optionally override the default name attached to a Build Scan. */
val buildScanUsername: Provider<String> =
dokkaProperty("build.scan.username")
.orElse(BUILD_SCAN_USERNAME_DEFAULT)
.map(String::trim)

develocity {
val buildScanEnabled = buildScanEnabled.get()

if (buildScanEnabled) {
plugins.apply("com.gradle.common-custom-user-data-gradle-plugin")
}

server = "https://ge.jetbrains.com/"

buildScan {
publishing {
onlyIf { buildScanEnabled }
}

capture {
buildLogging = buildScanEnabled
fileFingerprints = buildScanEnabled
testLogging = buildScanEnabled
}

val overriddenName = buildScanUsername.orNull
obfuscation {
ipAddresses { _ -> listOf("0.0.0.0") }
hostname { _ -> "concealed" }
username { originalUsername ->
when {
buildingOnTeamCity -> "TeamCity"
buildingOnGitHub -> "GitHub"
buildingOnCi -> "CI"
!overriddenName.isNullOrBlank() -> overriddenName
overriddenName == BUILD_SCAN_USERNAME_DEFAULT -> originalUsername
else -> "unknown"
}
}
}
}
}
//endregion

//region Gradle Build Cache
val buildCacheLocalEnabled: Provider<Boolean> =
dokkaProperty("build.cache.local.enabled", String::toBoolean)
.orElse(!buildingOnCi)
val buildCacheLocalDirectory: Provider<String> =
dokkaProperty("build.cache.local.directory")
val buildCachePushEnabled: Provider<Boolean> =
dokkaProperty("build.cache.push", String::toBoolean)
.orElse(buildingOnTeamCity)

buildCache {
local {
isEnabled = buildCacheLocalEnabled.get()
if (buildCacheLocalDirectory.orNull != null) {
directory = buildCacheLocalDirectory.get()
}
}
remote(develocity.buildCache) {
isPush = buildCachePushEnabled.get()
}
}
//endregion

//endregion

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1ba220d

Please sign in to comment.