-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build config/build scans and build cache #451
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8f7e00f
Added Gradle Build Scans
dkrasnoff 68e5567
Added Gradle Build Cache
dkrasnoff fb52693
Update README.md
dkrasnoff 9f19a76
Update build-settings-logic/src/main/kotlin/Utils.kt
dkrasnoff 50047b0
Update build-settings-logic/settings.gradle.kts
dkrasnoff 77a1ded
Update build-settings-logic/src/main/kotlin/gradle-build-scan.setting…
dkrasnoff 200966b
Renamed atomicfu settings plugins
dkrasnoff 9131de9
fixup! Update build-settings-logic/src/main/kotlin/Utils.kt
dkrasnoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation(libs.gradle.develocity) | ||
} |
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,16 @@ | ||
rootProject.name = "build-settings-logic" | ||
|
||
dependencyResolutionManagement { | ||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
versionCatalogs { | ||
create("libs") { | ||
from(files("../gradle/libs.versions.toml")) | ||
} | ||
} | ||
} | ||
|
||
apply(from = "src/main/kotlin/atomicfu-gradle-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,34 @@ | ||
/* | ||
* 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 | ||
|
||
|
||
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 | ||
|
||
// NOTE: build scan properties are documented in README.md | ||
val Settings.buildScanEnabled: Provider<Boolean> | ||
get() = | ||
atomicfuProperty("build.scan.enabled", String::toBoolean) | ||
.orElse(buildingOnCi) | ||
|
||
internal const val DEFAULT_ATOMICFU_USER_NAME = "<default>" | ||
|
||
/** | ||
* Optionaly override the default name attached to a Build Scan. | ||
*/ | ||
val Settings.buildScanUsername: Provider<String> | ||
get() = | ||
atomicfuProperty("build.scan.username") | ||
.orElse(DEFAULT_ATOMICFU_USER_NAME) | ||
.map(String::trim) | ||
|
||
internal fun Settings.atomicfuProperty(name: String): Provider<String> = | ||
providers.gradleProperty("org.jetbrains.atomicfu.$name") | ||
|
||
internal fun <T : Any> Settings.atomicfuProperty(name: String, convert: (String) -> T): Provider<T> = | ||
atomicfuProperty(name).map(convert) | ||
|
66 changes: 66 additions & 0 deletions
66
build-settings-logic/src/main/kotlin/atomicfu-gradle-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,66 @@ | ||
/** | ||
* Gradle Build Cache conventions. | ||
* | ||
* Because Atomicfu uses Composite Builds, Build Cache must be configured consistently on | ||
* - the root settings.gradle.kts, | ||
* - and the settings.gradle.kts of any projects added with `pluginManagement { includedBuild("...") }` | ||
* | ||
* See https://docs.gradle.org/8.8/userguide/build_cache.html#sec:build_cache_composite | ||
* | ||
* ⚠️ This file _must_ be applicable as a script plugin and so _must not_ depend on other source files. | ||
* | ||
* Based on https://github.com/JetBrains/kotlin/blob/2675531624d42851af502a993bbefd65ee3e38ef/repo/gradle-settings-conventions/build-cache/src/main/kotlin/build-cache.settings.gradle.kts | ||
*/ | ||
|
||
// Don't remove or move to *.kt files these functions and variables | ||
// they are required for applying this plugin as convention plugin to `build-settings-logic` settings file | ||
internal fun Settings.atomicfuProperty(name: String): Provider<String> = | ||
providers.gradleProperty("org.jetbrains.atomicfu.$name") | ||
|
||
internal fun <T : Any> Settings.atomicfuProperty(name: String, convert: (String) -> T): Provider<T> = | ||
atomicfuProperty(name).map(convert) | ||
|
||
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 | ||
|
||
/** | ||
* Disable Local Cache on CI, because CI machines are short-lived, so local caching doesn't help a lot. | ||
* Also, to force CI machines to update the remote cache. | ||
*/ | ||
val buildCacheLocalEnabled: Provider<Boolean> = | ||
atomicfuProperty("build.cache.local.enabled", String::toBoolean) | ||
.orElse(!buildingOnCi) | ||
|
||
val buildCacheLocalDirectory: Provider<String> = | ||
atomicfuProperty("build.cache.local.directory") | ||
|
||
val buildCachePushEnabled: Provider<Boolean> = | ||
atomicfuProperty("build.cache.push", String::toBoolean) | ||
.orElse(buildingOnTeamCity) | ||
|
||
val buildCacheUser: Provider<String> = | ||
providers.gradleProperty("build.cache.user") | ||
|
||
val buildCachePassword: Provider<String> = | ||
providers.gradleProperty("build.cache.password") | ||
|
||
buildCache { | ||
local { | ||
isEnabled = buildCacheLocalEnabled.get() | ||
if (buildCacheLocalDirectory.orNull != null) { | ||
directory = buildCacheLocalDirectory.get() | ||
} | ||
} | ||
remote<HttpBuildCache> { | ||
url = uri("https://ge.jetbrains.com/cache/") | ||
isPush = buildCachePushEnabled.get() | ||
|
||
if (buildCacheUser.isPresent && | ||
buildCachePassword.isPresent | ||
) { | ||
credentials.username = buildCacheUser.get() | ||
credentials.password = buildCachePassword.get() | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
build-settings-logic/src/main/kotlin/atomicfu-gradle-build-scan.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,34 @@ | ||
// this is a settings convention plugin for Gradle Develocity | ||
|
||
plugins { | ||
id("com.gradle.develocity") | ||
} | ||
|
||
develocity { | ||
if (buildScanEnabled.get()) { | ||
val overriddenName = buildScanUsername.orNull | ||
buildScan { | ||
server = "https://ge.jetbrains.com/" | ||
publishing.onlyIf { true } | ||
capture { | ||
fileFingerprints = true | ||
buildLogging = true | ||
uploadInBackground = true | ||
} | ||
obfuscation { | ||
ipAddresses { _ -> listOf("0.0.0.0") } | ||
hostname { _ -> "concealed" } | ||
username { originalUsername -> | ||
when { | ||
buildingOnTeamCity -> "TeamCity" | ||
buildingOnGitHub -> "GitHub" | ||
buildingOnCi -> "CI" | ||
!overriddenName.isNullOrBlank() && overriddenName != DEFAULT_ATOMICFU_USER_NAME -> overriddenName | ||
overriddenName == DEFAULT_ATOMICFU_USER_NAME -> 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
rootProject.name = "buildSrc" | ||
|
||
dependencyResolutionManagement { | ||
|
||
@Suppress("UnstableApiUsage") | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These utils are only used in
gradle-build-scan.settings.gradle.kts
- maybe they should be moved into the same file?Alternatively, I think a more descriptive name would be nice. What about
BuildScanProperties.kt
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave it as is for the future, if we have some shared logic, it could be placed in
Utils.kt
file