Skip to content

Commit 97af6d4

Browse files
committed
Added build cache and develocity plugin
1 parent 78a153a commit 97af6d4

File tree

10 files changed

+159
-0
lines changed

10 files changed

+159
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ detekt/reports/**
3232

3333
# Ignore kover reports
3434
/kover
35+
36+
scan-journal.log

compiler-plugin/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pluginManagement {
1313

1414
plugins {
1515
id("settings-conventions")
16+
id("conventions-develocity")
1617
}
1718

1819
includeRootAsPublic()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
plugins {
6+
alias(libs.plugins.gradle.kotlin.dsl)
7+
}
8+
9+
configurations.configureEach {
10+
resolutionStrategy {
11+
force(libs.kotlin.reflect)
12+
force(libs.kotlin.stdlib)
13+
force(libs.kotlin.stdlib.jdk7)
14+
force(libs.kotlin.stdlib.jdk8)
15+
}
16+
}
17+
18+
repositories {
19+
mavenCentral()
20+
gradlePluginPortal()
21+
}
22+
23+
dependencies {
24+
implementation("com.gradle:develocity-gradle-plugin:3.17")
25+
implementation("com.gradle:common-custom-user-data-gradle-plugin:2.0.1")
26+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import java.util.*
6+
7+
plugins {
8+
id("com.gradle.develocity")
9+
id("com.gradle.common-custom-user-data-gradle-plugin")
10+
}
11+
12+
develocity {
13+
val startParameter = gradle.startParameter
14+
val scanJournal = File(settingsDir, "scan-journal.log")
15+
16+
server = DEVELOCITY_SERVER
17+
18+
buildScan {
19+
uploadInBackground = !isCIRun
20+
21+
// obfuscate NIC since we don't want to expose user real IP (will be relevant without VPN)
22+
obfuscation {
23+
ipAddresses { addresses -> addresses.map { _ -> "0.0.0.0" } }
24+
}
25+
26+
capture {
27+
fileFingerprints = true
28+
}
29+
30+
buildScanPublished {
31+
scanJournal.appendText("${Date()}$buildScanUri$startParameter\n")
32+
}
33+
34+
publishing.onlyIf { true }
35+
}
36+
}
37+
38+
buildCache {
39+
if (isCIRun) {
40+
local {
41+
isEnabled = false
42+
}
43+
}
44+
45+
remote(develocity.buildCache) {
46+
isPush = isCIRun
47+
isEnabled = true
48+
}
49+
}
50+
51+
enrichTeamCityData()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import com.gradle.develocity.agent.gradle.DevelocityConfiguration
6+
import org.gradle.api.initialization.Settings
7+
8+
fun Settings.enrichTeamCityData() {
9+
val ge = extensions.getByType(DevelocityConfiguration::class.java)
10+
11+
gradle.projectsEvaluated {
12+
if (isCIRun) {
13+
val buildTypeId = "teamcity.buildType.id"
14+
val buildId = "teamcity.build.id"
15+
16+
if (gradle.rootProject.hasProperty(buildId) && gradle.rootProject.hasProperty(buildTypeId)) {
17+
val buildIdValue = gradle.rootProject.property(buildId).toString()
18+
val teamCityBuildNumber = java.net.URLEncoder.encode(buildIdValue, Charsets.UTF_8)
19+
val teamCityBuildTypeId = gradle.rootProject.property(buildTypeId)
20+
21+
ge.buildScan.link(
22+
"kotlinx.rpc TeamCity build",
23+
"${TEAMCITY_URL}/buildConfiguration/${teamCityBuildTypeId}/${teamCityBuildNumber}"
24+
)
25+
}
26+
27+
if (gradle.rootProject.hasProperty(buildId)) {
28+
ge.buildScan.value("CI build id", gradle.rootProject.property(buildId) as String)
29+
}
30+
}
31+
32+
if (!isCIRun) {
33+
// Git commit id
34+
val commitId = execute("git rev-parse --verify HEAD")
35+
if (commitId.isNotEmpty()) {
36+
ge.buildScan.value("Git Commit ID", commitId)
37+
ge.buildScan.link("GitHub Commit Link", "$GITHUB_REPO/tree/$commitId")
38+
}
39+
40+
// Git branch name
41+
val branchName = execute("git rev-parse --abbrev-ref HEAD")
42+
if (branchName.isNotEmpty()) {
43+
ge.buildScan.value("Git Branch Name", branchName)
44+
ge.buildScan.link("GitHub Branch Link", "$GITHUB_REPO/tree/$branchName")
45+
}
46+
47+
// Git dirty local state
48+
val status = execute("git status --porcelain")
49+
if (status.isNotEmpty()) {
50+
ge.buildScan.value("Git Status", status)
51+
}
52+
}
53+
}
54+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import org.gradle.api.initialization.Settings
6+
7+
@Suppress("UnstableApiUsage")
8+
fun Settings.execute(cmd: String): String {
9+
return settings.providers.exec {
10+
commandLine(cmd.split(" "))
11+
}.standardOutput.asText.get().trim()
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
const val DEVELOCITY_SERVER = "https://ge.jetbrains.com"
6+
const val GITHUB_REPO = "https://github.com/Kotlin/kotlinx-rpc"
7+
const val TEAMCITY_URL = "https://krpc.teamcity.com"
8+
9+
val isCIRun = System.getenv("TEAMCITY_VERSION") != null

gradle-conventions-settings/settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ rootProject.name = "gradle-conventions-settings"
66

77
// Code below is a hack because a chicken-egg problem, I can't use myself as a settings-plugin
88
apply(from = "src/main/kotlin/settings-conventions.settings.gradle.kts")
9+
10+
include(":develocity")

ksp-plugin/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pluginManagement {
1313

1414
plugins {
1515
id("settings-conventions")
16+
id("conventions-develocity")
1617
}
1718

1819
includeRootAsPublic()

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pluginManagement {
3636
plugins {
3737
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
3838
id("settings-conventions")
39+
id("conventions-develocity")
3940
}
4041

4142
dependencyResolutionManagement {

0 commit comments

Comments
 (0)