Skip to content

Commit c2c78de

Browse files
authored
Fix config cache for build command (#4157)
* Fix config cache for build command * Fix shadowing * Add gradle key for config cache in system tests * Cache buildSrc on CI
1 parent 5e31a6b commit c2c78de

File tree

16 files changed

+77
-43
lines changed

16 files changed

+77
-43
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ jobs:
2929
distribution: 'temurin'
3030
java-version: '17'
3131

32+
# Workaround for https://github.com/gradle/actions/issues/21 to use config cache
33+
- name: Cache buildSrc
34+
uses: actions/cache@v4
35+
with:
36+
path: buildSrc/build
37+
key: build-logic-${{ hashFiles('buildSrc/src/**', 'buildSrc/build.gradle.kts','buildSrc/settings.gradle.kts') }}
38+
3239
- name: Setup Gradle
3340
uses: gradle/actions/setup-gradle@aa23778d2dc6f6556fcc7164e99babbd8c3134e4 # pin@v3
3441
with:

.github/workflows/system-tests-backend.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
continue-on-error: true
1717
env:
1818
SENTRY_URL: http://127.0.0.1:8000
19+
GRADLE_ENCRYPTION_KEY: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
1920
strategy:
2021
fail-fast: false
2122
matrix:
@@ -59,6 +60,7 @@ jobs:
5960
uses: gradle/actions/setup-gradle@aa23778d2dc6f6556fcc7164e99babbd8c3134e4 # pin@v3
6061
with:
6162
gradle-home-cache-cleanup: true
63+
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
6264

6365
- name: Exclude android modules from build
6466
run: |
@@ -91,11 +93,11 @@ jobs:
9193
9294
- name: Build server jar
9395
run: |
94-
./gradlew :sentry-samples:${{ matrix.sample }}:bootJar --no-configuration-cache
96+
./gradlew :sentry-samples:${{ matrix.sample }}:bootJar
9597
9698
- name: Build agent jar
9799
run: |
98-
./gradlew :sentry-opentelemetry:sentry-opentelemetry-agent:assemble --no-configuration-cache
100+
./gradlew :sentry-opentelemetry:sentry-opentelemetry-agent:assemble
99101
100102
- name: Start server and run integration test for sentry-cli commands
101103
run: |

build.gradle.kts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ subprojects {
179179

180180
tasks.named("distZip").configure {
181181
this.dependsOn("publishToMavenLocal")
182+
val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile
182183
this.doLast {
183-
val file = this.project.layout.buildDirectory.file("distributions${sep}${this.project.name}-${this.project.version}.zip").get().asFile
184184
if (!file.exists()) throw IllegalStateException("Distribution file: ${file.absolutePath} does not exist")
185185
if (file.length() == 0L) throw IllegalStateException("Distribution file: ${file.absolutePath} is empty")
186186
}
@@ -300,21 +300,6 @@ gradle.taskGraph.whenReady {
300300
}
301301
}
302302

303-
private val androidLibs = setOf(
304-
"sentry-android-core",
305-
"sentry-android-ndk",
306-
"sentry-android-fragment",
307-
"sentry-android-navigation",
308-
"sentry-android-timber",
309-
"sentry-compose-android",
310-
"sentry-android-sqlite",
311-
"sentry-android-replay"
312-
)
313-
314-
private val androidXLibs = listOf(
315-
"androidx.core:core"
316-
)
317-
318303
/*
319304
* Adapted from https://github.com/androidx/androidx/blob/c799cba927a71f01ea6b421a8f83c181682633fb/buildSrc/private/src/main/kotlin/androidx/build/MavenUploadHelper.kt#L524-L549
320305
*
@@ -334,7 +319,6 @@ private val androidXLibs = listOf(
334319
*/
335320

336321
// Workaround for https://github.com/gradle/gradle/issues/3170
337-
@Suppress("UnstableApiUsage")
338322
fun MavenPublishBaseExtension.assignAarTypes() {
339323
pom {
340324
withXml {
@@ -356,9 +340,9 @@ fun MavenPublishBaseExtension.assignAarTypes() {
356340
} as? Node
357341
val artifactIdValue = artifactId?.children()?.firstOrNull() as? String
358342

359-
if (artifactIdValue in androidLibs) {
343+
if (artifactIdValue in Config.BuildScript.androidLibs) {
360344
dep.appendNode("type", "aar")
361-
} else if ("$groupValue:$artifactIdValue" in androidXLibs) {
345+
} else if ("$groupValue:$artifactIdValue" in Config.BuildScript.androidXLibs) {
362346
dep.appendNode("type", "aar")
363347
}
364348
}

buildSrc/src/main/java/Config.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ object Config {
2727
val grettyVersion = "4.0.0"
2828
val gradleMavenPublishPlugin = "com.vanniktech.maven.publish"
2929
val gradleMavenPublishPluginVersion = "0.30.0"
30-
val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20"
30+
val dokkaPlugin = "org.jetbrains.dokka:dokka-gradle-plugin:2.0.0"
3131
val dokkaPluginAlias = "org.jetbrains.dokka"
32+
val dokkaPluginJavadocAlias = "org.jetbrains.dokka-javadoc"
3233
val composeGradlePlugin = "org.jetbrains.compose:compose-gradle-plugin:$composeVersion"
3334
val commonsCompressOverride = "org.apache.commons:commons-compress:1.25.0"
3435
}
@@ -272,4 +273,21 @@ object Config {
272273
val errorprone = "com.google.errorprone:error_prone_core:2.11.0"
273274
val errorProneNullAway = "com.uber.nullaway:nullaway:0.9.5"
274275
}
276+
277+
object BuildScript {
278+
val androidLibs = setOf(
279+
"sentry-android-core",
280+
"sentry-android-ndk",
281+
"sentry-android-fragment",
282+
"sentry-android-navigation",
283+
"sentry-android-timber",
284+
"sentry-compose-android",
285+
"sentry-android-sqlite",
286+
"sentry-android-replay"
287+
)
288+
289+
val androidXLibs = listOf(
290+
"androidx.core:core"
291+
)
292+
}
275293
}

buildSrc/src/main/java/Publication.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ private object Consts {
1111
fun DistributionContainer.configureForMultiplatform(project: Project) {
1212
val sep = File.separator
1313
val version = project.properties["versionName"].toString()
14+
val name = project.name
1415

1516
this.maybeCreate("android").contents {
1617
from("build${sep}publications${sep}androidRelease") {
17-
renameModule(project.name, "android", version = version)
18+
renameModule(name, "android", version = version)
1819
}
1920
from("build${sep}outputs${sep}aar") {
2021
include("*-release*")
@@ -32,7 +33,7 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
3233
}
3334
this.getByName("main").contents {
3435
from("build${sep}publications${sep}kotlinMultiplatform") {
35-
renameModule(project.name, version = version)
36+
renameModule(name, version = version)
3637
}
3738
from("build${sep}kotlinToolingMetadata")
3839
from("build${sep}libs") {
@@ -48,7 +49,7 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
4849
this.maybeCreate("desktop").contents {
4950
// kotlin multiplatform modules
5051
from("build${sep}publications${sep}desktop") {
51-
renameModule(project.name, "desktop", version = version)
52+
renameModule(name, "desktop", version = version)
5253
}
5354
from("build${sep}libs") {
5455
include("*desktop*")
@@ -69,27 +70,28 @@ fun DistributionContainer.configureForMultiplatform(project: Project) {
6970
fun DistributionContainer.configureForJvm(project: Project) {
7071
val sep = File.separator
7172
val version = project.properties["versionName"].toString()
73+
val name = project.name
7274

7375
this.getByName("main").contents {
7476
// non android modules
7577
from("build${sep}libs")
7678
from("build${sep}publications${sep}maven") {
77-
renameModule(project.name, version = version)
79+
renameModule(name, version = version)
7880
}
7981
// android modules
8082
from("build${sep}outputs${sep}aar") {
8183
include("*-release*")
8284
}
8385
from("build${sep}publications${sep}release") {
84-
renameModule(project.name, version = version)
86+
renameModule(name, version = version)
8587
}
8688
from("build${sep}intermediates${sep}java_doc_jar${sep}release") {
8789
include("*javadoc*")
88-
rename { it.replace("release", "${project.name}-$version") }
90+
rename { it.replace("release", "$name-$version") }
8991
}
9092
from("build${sep}intermediates${sep}source_jar${sep}release") {
9193
include("*sources*")
92-
rename { it.replace("release", "${project.name}-$version") }
94+
rename { it.replace("release", "$name-$version") }
9395
}
9496
}
9597
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ org.gradle.parallel=true
55
org.gradle.configureondemand=true
66
org.gradle.configuration-cache=true
77

8+
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
9+
810
# Daemons workers
911
org.gradle.workers.max=2
1012

sentry-android-core/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ android {
2626
}
2727

2828
buildTypes {
29-
getByName("debug")
29+
getByName("debug") {
30+
consumerProguardFiles("proguard-rules.pro")
31+
}
3032
getByName("release") {
3133
consumerProguardFiles("proguard-rules.pro")
3234
}

sentry-android-fragment/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ android {
2121
}
2222

2323
buildTypes {
24-
getByName("debug")
24+
getByName("debug") {
25+
consumerProguardFiles("proguard-rules.pro")
26+
}
2527
getByName("release") {
2628
consumerProguardFiles("proguard-rules.pro")
2729
}

sentry-android-navigation/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ android {
2121
}
2222

2323
buildTypes {
24-
getByName("debug")
24+
getByName("debug") {
25+
consumerProguardFiles("proguard-rules.pro")
26+
}
2527
getByName("release") {
2628
consumerProguardFiles("proguard-rules.pro")
2729
}

sentry-android-ndk/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ android {
2626
}
2727

2828
buildTypes {
29-
getByName("debug")
29+
getByName("debug") {
30+
consumerProguardFiles("proguard-rules.pro")
31+
}
3032
getByName("release") {
3133
consumerProguardFiles("proguard-rules.pro")
3234
}

0 commit comments

Comments
 (0)