-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into KT-64377/java-test-…
…suites
- Loading branch information
Showing
13 changed files
with
260 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
description = "Conventions for use in settings.gradle.kts scripts" | ||
|
||
dependencies { | ||
implementation(libs.gradlePlugin.gradle.enterprise) | ||
implementation(libs.gradlePlugin.gradle.customUserData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import org.gradle.api.initialization.resolve.RepositoriesMode.PREFER_SETTINGS | ||
|
||
/* | ||
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
rootProject.name = "build-settings-logic" | ||
|
||
pluginManagement { | ||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
} | ||
|
||
@Suppress("UnstableApiUsage") | ||
dependencyResolutionManagement { | ||
repositoriesMode.set(PREFER_SETTINGS) | ||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
build-settings-logic/src/main/kotlin/DokkaBuildSettingsProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import org.gradle.api.initialization.Settings | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.provider.ProviderFactory | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.findByType | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Shared properties in `settings.gradle.kts` files. | ||
* | ||
* Fetch an instance using [DokkaBuildSettingsProperties.Companion.dokkaBuildSettingsProperties]. | ||
*/ | ||
abstract class DokkaBuildSettingsProperties @Inject constructor( | ||
private val providers: ProviderFactory | ||
) { | ||
val buildingOnTeamCity: Boolean = System.getenv("TEAMCITY_VERSION") != null | ||
val buildingOnCi: Boolean = System.getenv("CI") != null || buildingOnTeamCity | ||
|
||
|
||
//region Gradle Build Scan | ||
// NOTE: build scan properties are documented in CONTRIBUTING.md | ||
/** If unset, the user has not opted in to publish Build Scans. */ | ||
val buildScanUrl: Provider<String> = | ||
dokkaProperty("build.scan.url") | ||
|
||
/** 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) | ||
//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 buildCacheUrl: Provider<String> = | ||
dokkaProperty("build.cache.url").map(String::trim) | ||
val buildCachePushEnabled: Provider<Boolean> = | ||
dokkaProperty("build.cache.push", String::toBoolean) | ||
.orElse(buildingOnTeamCity) | ||
val buildCacheUser: Provider<String> = | ||
dokkaProperty("build.cache.user") | ||
val buildCachePassword: Provider<String> = | ||
dokkaProperty("build.cache.password") | ||
//endregion | ||
|
||
|
||
private fun dokkaProperty(name: String): Provider<String> = | ||
providers.gradleProperty("org.jetbrains.dokka.$name") | ||
|
||
private fun <T : Any> dokkaProperty(name: String, convert: (String) -> T): Provider<T> = | ||
dokkaProperty(name).map(convert) | ||
|
||
companion object { | ||
const val BUILD_SCAN_USERNAME_DEFAULT = "<default>" | ||
|
||
val Settings.dokkaBuildSettingsProperties: DokkaBuildSettingsProperties | ||
get() { | ||
return extensions.findByType<DokkaBuildSettingsProperties>() | ||
?: extensions.create<DokkaBuildSettingsProperties>("dokkaBuildSettingsProperties") | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
build-settings-logic/src/main/kotlin/dokkasettings.build-cache.settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import DokkaBuildSettingsProperties.Companion.dokkaBuildSettingsProperties | ||
|
||
/** | ||
* Gradle Build Cache conventions. | ||
* | ||
* See [DokkaBuildSettingsProperties] for properties. | ||
* | ||
* Because Dokka uses Composite Builds, Build Cache should only be configured on the root `settings.gradle.kts`. | ||
* See https://docs.gradle.org/8.4/userguide/build_cache.html#sec:build_cache_composite. | ||
* | ||
* Based on https://github.com/JetBrains/kotlin/blob/2675531624d42851af502a993bbefd65ee3e38ef/repo/gradle-settings-conventions/build-cache/src/main/kotlin/build-cache.settings.gradle.kts | ||
*/ | ||
|
||
val buildSettingsProps = dokkaBuildSettingsProperties | ||
|
||
buildCache { | ||
local { | ||
isEnabled = buildSettingsProps.buildCacheLocalEnabled.get() | ||
if (buildSettingsProps.buildCacheLocalDirectory.orNull != null) { | ||
directory = buildSettingsProps.buildCacheLocalDirectory.get() | ||
} | ||
} | ||
|
||
val remoteBuildCacheUrl = buildSettingsProps.buildCacheUrl.orNull | ||
if (!remoteBuildCacheUrl.isNullOrEmpty()) { | ||
remote<HttpBuildCache> { | ||
url = uri(remoteBuildCacheUrl) | ||
isPush = buildSettingsProps.buildCachePushEnabled.get() | ||
|
||
if (buildSettingsProps.buildCacheUser.isPresent && | ||
buildSettingsProps.buildCachePassword.isPresent | ||
) { | ||
credentials.username = buildSettingsProps.buildCacheUser.get() | ||
credentials.password = buildSettingsProps.buildCachePassword.get() | ||
} | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
build-settings-logic/src/main/kotlin/dokkasettings.gradle-enterprise.settings.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2014-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
import DokkaBuildSettingsProperties.Companion.BUILD_SCAN_USERNAME_DEFAULT | ||
import DokkaBuildSettingsProperties.Companion.dokkaBuildSettingsProperties | ||
|
||
/** | ||
* Gradle Enterprise conventions. | ||
* | ||
* See [DokkaBuildSettingsProperties] for properties. | ||
* | ||
* To use JetBrain's Gradle Enterprise set the URL | ||
* https://ge.jetbrains.com/ | ||
* in `$GRADLE_USER_HOME/gradle.properties`† | ||
* | ||
* ```properties | ||
* org.jetbrains.dokka.build.scan.url=https\://ge.jetbrains.com/ | ||
* ``` | ||
* | ||
* Based on https://github.com/JetBrains/kotlin/blob/19073b96a7ed53dbda61337465ca898c1482e090/repo/gradle-settings-conventions/gradle-enterprise/src/main/kotlin/gradle-enterprise.settings.gradle.kts | ||
* | ||
* † _See [`GRADLE_USER_HOME`](https://docs.gradle.org/8.5/userguide/directory_layout.html#dir:gradle_user_home)_ | ||
*/ | ||
|
||
plugins { | ||
id("com.gradle.enterprise") | ||
id("com.gradle.common-custom-user-data-gradle-plugin") apply false | ||
} | ||
|
||
val buildSettingsProps = dokkaBuildSettingsProperties | ||
|
||
val buildScanServer = buildSettingsProps.buildScanUrl.orNull?.ifBlank { null } | ||
|
||
if (buildScanServer != null) { | ||
plugins.apply("com.gradle.common-custom-user-data-gradle-plugin") | ||
} | ||
|
||
gradleEnterprise { | ||
buildScan { | ||
if (buildScanServer != null) { | ||
server = buildScanServer | ||
publishAlways() | ||
|
||
capture { | ||
isTaskInputFiles = true | ||
isBuildLogging = true | ||
isUploadInBackground = true | ||
} | ||
} | ||
|
||
val overriddenName = buildSettingsProps.buildScanUsername.orNull | ||
obfuscation { | ||
ipAddresses { _ -> listOf("0.0.0.0") } | ||
hostname { _ -> "concealed" } | ||
username { originalUsername -> | ||
when { | ||
buildSettingsProps.buildingOnTeamCity -> "TeamCity" | ||
buildSettingsProps.buildingOnCi -> "CI" | ||
overriddenName.isNullOrBlank() -> overriddenName | ||
overriddenName == BUILD_SCAN_USERNAME_DEFAULT -> originalUsername | ||
else -> "unknown" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.