Skip to content

Commit 04a10bf

Browse files
runningcodeclaude
andauthored
fix(config-cache): Resolve CLI path via ValueSource task input (GRADLE-70) (#1264)
* fix(config-cache): Resolve CLI path via ValueSource task input (GRADLE-70) The sentry-cli path was memoized in a static field on SentryCliProvider. That field survives across builds in the Gradle daemon and is not invalidated when switching branches, so a stale path pointing at a sentry-cli temp file from a previous checkout could be reused, causing "No such file or directory" failures when configuration caching is on. Remove the static memoization and stop threading the cli path through the configure() call chain. Each SentryCliExecTask now resolves the path itself in asSentryCliExec() via the existing cliExecutableProvider() ValueSource, which is properly invalidated on branch switches, and wires its own buildDirectory input. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * docs(changelog): Add entry for CLI path task-input fix (GRADLE-70) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8187fdf commit 04a10bf

20 files changed

Lines changed: 114 additions & 165 deletions

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Resolve the sentry-cli path as a task input instead of memoizing it in a static field, fixing stale-path build failures when switching branches with the configuration cache enabled ([#1264](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1264))
8+
- This fixed the issue where sentry-cli could not be found (`A problem occurred starting process 'command ../sentry-cliXXX.exe'`)
9+
310
## 6.10.0
411

512
### Features

plugin-build/src/main/kotlin/io/sentry/android/gradle/AndroidComponentsConfig.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fun ApplicationAndroidComponentsExtension.configure(
7777
}
7878

7979
if (extension.snapshots.enabled.get()) {
80-
variant.configureSnapshotsTasks(project, extension, cliExecutable, sentryOrg, sentryProject)
80+
variant.configureSnapshotsTasks(project, extension, sentryOrg, sentryProject)
8181
}
8282

8383
if (isVariantAllowed(extension, variant.name, variant.flavorName, variant.buildType)) {
@@ -106,7 +106,6 @@ fun ApplicationAndroidComponentsExtension.configure(
106106
sentryTelemetryProvider,
107107
paths,
108108
sourceFiles,
109-
cliExecutable,
110109
sentryOrg,
111110
sentryProject,
112111
)
@@ -118,7 +117,6 @@ fun ApplicationAndroidComponentsExtension.configure(
118117
extension,
119118
sentryTelemetryProvider,
120119
paths,
121-
cliExecutable,
122120
sentryOrg,
123121
sentryProject,
124122
)
@@ -139,7 +137,6 @@ fun ApplicationAndroidComponentsExtension.configure(
139137
project,
140138
extension,
141139
sentryTelemetryProvider,
142-
cliExecutable,
143140
sentryOrg,
144141
sentryProject,
145142
)
@@ -257,7 +254,6 @@ fun ApplicationAndroidComponentsExtension.configure(
257254
project,
258255
extension,
259256
sentryTelemetryProvider,
260-
cliExecutable,
261257
sentryOrg,
262258
sentryProject,
263259
)
@@ -297,7 +293,6 @@ private fun Variant.configureSourceBundleTasks(
297293
sentryTelemetryProvider: Provider<SentryTelemetryService>,
298294
paths: OutputPaths,
299295
sourceFiles: Provider<out Collection<Directory>>?,
300-
cliExecutable: Provider<String>,
301296
sentryOrg: String?,
302297
sentryProject: String?,
303298
): SourceContext.SourceContextTasks? {
@@ -313,7 +308,6 @@ private fun Variant.configureSourceBundleTasks(
313308
variant,
314309
paths,
315310
sourceFiles,
316-
cliExecutable,
317311
sentryOrg,
318312
sentryProject,
319313
taskSuffix,
@@ -354,7 +348,6 @@ private fun ApplicationVariant.configureProguardMappingsTasks(
354348
extension: SentryPluginExtension,
355349
sentryTelemetryProvider: Provider<SentryTelemetryService>,
356350
paths: OutputPaths,
357-
cliExecutable: Provider<String>,
358351
sentryOrg: String?,
359352
sentryProject: String?,
360353
): TaskProvider<SentryGenerateProguardUuidTask>? {
@@ -386,7 +379,6 @@ private fun ApplicationVariant.configureProguardMappingsTasks(
386379
extension,
387380
sentryTelemetryProvider,
388381
debug = extension.debug,
389-
cliExecutable = cliExecutable,
390382
generateUuidTask = generateUuidTask,
391383
sentryProperties = sentryProps,
392384
mappingFiles = mappings,
@@ -460,7 +452,6 @@ private fun ApplicationVariant.configureDistributionPropertiesTask(
460452
private fun ApplicationVariant.configureSnapshotsTasks(
461453
project: Project,
462454
extension: SentryPluginExtension,
463-
cliExecutable: Provider<String>,
464455
sentryOrg: String?,
465456
sentryProject: String?,
466457
) {
@@ -478,7 +469,6 @@ private fun ApplicationVariant.configureSnapshotsTasks(
478469
project = project,
479470
extension = extension,
480471
sentryTelemetryProvider = null,
481-
cliExecutable = cliExecutable,
482472
sentryOrgOverride = sentryOrg,
483473
sentryProjectOverride = sentryProject,
484474
applicationId = applicationId,
@@ -557,7 +547,6 @@ fun Variant.configureUploadAppTasks(
557547
project: Project,
558548
extension: SentryPluginExtension,
559549
sentryTelemetryProvider: Provider<SentryTelemetryService>,
560-
cliExecutable: Provider<String>,
561550
sentryOrg: String?,
562551
sentryProject: String?,
563552
): Pair<TaskProvider<SentryUploadAppArtifactTask>, TaskProvider<SentryUploadAppArtifactTask>> {
@@ -570,7 +559,6 @@ fun Variant.configureUploadAppTasks(
570559
extension,
571560
sentryTelemetryProvider,
572561
debug = extension.debug,
573-
cliExecutable = cliExecutable,
574562
appBundle = variant.bundle,
575563
apk = variant.apk,
576564
sentryOrg = sentryOrg?.let { project.provider { it } } ?: extension.org,

plugin-build/src/main/kotlin/io/sentry/android/gradle/SentryCliProvider.kt

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import org.gradle.api.tasks.Input
2424

2525
internal object SentryCliProvider {
2626

27-
@field:Volatile private var memoizedCliPath: String? = null
28-
2927
/**
3028
* Return the correct sentry-cli executable path to use for the given project. This will look for
3129
* a sentry-cli executable in a local node_modules in case it was put there by sentry-react-native
@@ -34,40 +32,26 @@ internal object SentryCliProvider {
3432
* without actually extracting it.
3533
*/
3634
@JvmStatic
37-
@Synchronized
3835
fun getSentryCliPath(
3936
projectDir: DirectoryProperty,
4037
projectBuildDir: DirectoryProperty,
4138
rootDir: DirectoryProperty,
4239
): String {
43-
val cliPath = memoizedCliPath
44-
if (!cliPath.isNullOrEmpty() && File(cliPath).exists()) {
45-
logger.info { "Using memoized cli path: $cliPath" }
46-
return cliPath
47-
}
48-
// If a path is provided explicitly use that first.
4940
logger.info { "Searching cli from sentry.properties file..." }
5041

5142
searchCliInPropertiesFile(projectDir, rootDir)?.let {
5243
logger.info { "cli Found: $it" }
53-
memoizedCliPath = it
5444
return@getSentryCliPath it
5545
} ?: logger.info { "sentry-cli not found in sentry.properties file" }
5646

57-
// next up try a packaged version of sentry-cli
5847
val cliResLocation = getCliLocationInResources()
5948
if (!cliResLocation.isNullOrBlank()) {
6049
logger.info { "cli present in resources: $cliResLocation" }
61-
// just provide the target extraction path
62-
// actual extraction will be done prior to task execution
63-
val extractedResourcePath =
64-
getCliResourcesExtractionPath(projectBuildDir).get().asFile.absolutePath
65-
memoizedCliPath = extractedResourcePath
66-
return extractedResourcePath
50+
return getCliResourcesExtractionPath(projectBuildDir).get().asFile.absolutePath
6751
}
6852

6953
logger.error { "Falling back to invoking `sentry-cli` from shell" }
70-
return "sentry-cli".also { memoizedCliPath = it }
54+
return "sentry-cli"
7155
}
7256

7357
private fun getCliLocationInResources(): String? {

plugin-build/src/main/kotlin/io/sentry/android/gradle/sourcecontext/BundleSourcesTask.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ abstract class BundleSourcesTask : SentryCliExecTask() {
7777
collectSourcesTask: TaskProvider<CollectSourcesTask>,
7878
output: Provider<Directory>,
7979
debug: Property<Boolean>,
80-
cliExecutable: Provider<String>,
8180
sentryOrg: Provider<String>,
8281
sentryProject: Provider<String>,
8382
sentryAuthToken: Property<String>,
@@ -95,7 +94,6 @@ abstract class BundleSourcesTask : SentryCliExecTask() {
9594
task.sentryAuthToken.set(sentryAuthToken)
9695
task.sentryUrl.set(sentryUrl)
9796
task.sourceDir.set(collectSourcesTask.flatMap { it.output })
98-
task.cliExecutable.set(cliExecutable)
9997
SentryPropertiesFileProvider.getPropertiesFilePath(project, variant)?.let {
10098
task.sentryProperties.set(File(it))
10199
}

plugin-build/src/main/kotlin/io/sentry/android/gradle/sourcecontext/SourceContext.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class SourceContext {
1717
variant: SentryVariant,
1818
paths: OutputPaths,
1919
sourceFiles: Provider<out Collection<Directory>>?,
20-
cliExecutable: Provider<String>,
2120
sentryOrg: String?,
2221
sentryProject: String?,
2322
taskSuffix: String,
@@ -54,7 +53,6 @@ class SourceContext {
5453
collectSourcesTask,
5554
output = paths.bundleDir,
5655
extension.debug,
57-
cliExecutable,
5856
sentryOrg?.let { project.provider { it } } ?: extension.org,
5957
sentryProject?.let { project.provider { it } } ?: extension.projectName,
6058
extension.authToken,
@@ -71,7 +69,6 @@ class SourceContext {
7169
variant,
7270
bundleSourcesTask,
7371
extension.debug,
74-
cliExecutable,
7572
extension.autoUploadSourceContext,
7673
sentryOrg?.let { project.provider { it } } ?: extension.org,
7774
sentryProject?.let { project.provider { it } } ?: extension.projectName,

plugin-build/src/main/kotlin/io/sentry/android/gradle/sourcecontext/UploadSourceBundleTask.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ abstract class UploadSourceBundleTask : SentryCliExecTask() {
6868
variant: SentryVariant,
6969
bundleSourcesTask: TaskProvider<BundleSourcesTask>,
7070
debug: Property<Boolean>,
71-
cliExecutable: Provider<String>,
7271
autoUploadSourceContext: Property<Boolean>,
7372
sentryOrg: Provider<String>,
7473
sentryProject: Provider<String>,
@@ -87,7 +86,6 @@ abstract class UploadSourceBundleTask : SentryCliExecTask() {
8786
task.sentryAuthToken.set(sentryAuthToken)
8887
task.sentryUrl.set(sentryUrl)
8988
task.sourceBundleDir.set(bundleSourcesTask.flatMap { it.output })
90-
task.cliExecutable.set(cliExecutable)
9189
task.autoUploadSourceContext.set(autoUploadSourceContext)
9290
SentryPropertiesFileProvider.getPropertiesFilePath(project, variant)?.let {
9391
task.sentryProperties.set(File(it))

plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryCliExecTask.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ abstract class SentryCliExecTask : Exec() {
2222

2323
@get:Input @get:Optional abstract val debug: Property<Boolean>
2424

25-
@get:Input abstract val cliExecutable: Property<String>
26-
2725
@get:InputFile
2826
@get:Optional
2927
@get:PathSensitive(PathSensitivity.RELATIVE)
@@ -39,7 +37,9 @@ abstract class SentryCliExecTask : Exec() {
3937

4038
@get:Internal abstract val sentryTelemetryService: Property<SentryTelemetryService>
4139

42-
private val buildDirectory: DirectoryProperty = project.layout.buildDirectory
40+
@get:Input abstract val cliExecutable: Property<String>
41+
42+
@get:Internal abstract val buildDirectory: DirectoryProperty
4343

4444
override fun exec() {
4545
computeCommandLineArgs().let {
@@ -92,8 +92,7 @@ abstract class SentryCliExecTask : Exec() {
9292
args.add(1, "/c")
9393
}
9494

95-
val cliPath = SentryCliProvider.maybeExtractFromResources(buildDirectory, cliExecutable.get())
96-
args.add(cliPath)
95+
args.add(SentryCliProvider.maybeExtractFromResources(buildDirectory, cliExecutable.get()))
9796
args.addAll(preArgs())
9897

9998
getArguments(args)

plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryUploadAppArtifactTask.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ abstract class SentryUploadAppArtifactTask @Inject constructor(objectFactory: Ob
101101
debug: Property<Boolean>,
102102
appBundle: Provider<RegularFile>,
103103
apk: Provider<Directory>,
104-
cliExecutable: Provider<String>,
105104
sentryProperties: String?,
106105
sentryOrg: Provider<String>,
107106
sentryProject: Provider<String>,
@@ -118,7 +117,7 @@ abstract class SentryUploadAppArtifactTask @Inject constructor(objectFactory: Ob
118117
) { task ->
119118
task.workingDir(project.rootDir)
120119
task.debug.set(debug)
121-
task.cliExecutable.set(cliExecutable)
120+
122121
task.sentryProperties.set(sentryProperties?.let { file -> project.file(file) })
123122
task.bundle.set(appBundle)
124123
task.sentryOrganization.set(sentryOrg)
@@ -148,7 +147,7 @@ abstract class SentryUploadAppArtifactTask @Inject constructor(objectFactory: Ob
148147
) { task ->
149148
task.workingDir(project.rootDir)
150149
task.debug.set(debug)
151-
task.cliExecutable.set(cliExecutable)
150+
152151
task.sentryProperties.set(sentryProperties?.let { file -> project.file(file) })
153152
task.apk.set(apk)
154153
task.sentryOrganization.set(sentryOrg)

plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryUploadNativeSymbolsTask.kt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ abstract class SentryUploadNativeSymbolsTask : SentryCliExecTask() {
3131

3232
@get:Internal abstract val variantName: Property<String>
3333

34-
private val buildDir: Provider<File> = project.layout.buildDirectory.asFile
35-
3634
override fun getArguments(args: MutableList<String>) {
3735
args.add("debug-files")
3836
args.add("upload")
@@ -44,7 +42,8 @@ abstract class SentryUploadNativeSymbolsTask : SentryCliExecTask() {
4442
// eg absoluteProjectFolderPath/build/intermediates/merged_native_libs/{variantName}
4543
// where {variantName} could be debug/release...
4644
args.add(
47-
File(buildDir.get(), "intermediates/merged_native_libs/${variantName.get()}").absolutePath
45+
File(buildDirectory.get().asFile, "intermediates/merged_native_libs/${variantName.get()}")
46+
.absolutePath
4847
)
4948

5049
// Only include sources if includeNativeSources is enabled, as this is opt-in feature
@@ -60,7 +59,6 @@ abstract class SentryUploadNativeSymbolsTask : SentryCliExecTask() {
6059
sentryTelemetryProvider: Provider<SentryTelemetryService>,
6160
variantName: String,
6261
debug: Property<Boolean>,
63-
cliExecutable: Provider<String>,
6462
sentryProperties: String?,
6563
sentryOrg: Provider<String>,
6664
sentryProject: Provider<String>,
@@ -78,7 +76,6 @@ abstract class SentryUploadNativeSymbolsTask : SentryCliExecTask() {
7876
task.workingDir(project.rootDir)
7977
task.debug.set(debug)
8078
task.autoUploadNativeSymbol.set(autoUploadNativeSymbols)
81-
task.cliExecutable.set(cliExecutable)
8279
task.sentryProperties.set(sentryProperties?.let { file -> project.file(file) })
8380
task.includeNativeSources.set(includeNativeSources)
8481
task.variantName.set(variantName)
@@ -99,7 +96,6 @@ fun SentryVariant.configureNativeSymbolsTask(
9996
project: Project,
10097
extension: SentryPluginExtension,
10198
sentryTelemetryProvider: Provider<SentryTelemetryService>,
102-
cliExecutable: Provider<String>,
10399
sentryOrg: String?,
104100
sentryProject: String?,
105101
) {
@@ -113,7 +109,6 @@ fun SentryVariant.configureNativeSymbolsTask(
113109
sentryTelemetryProvider = sentryTelemetryProvider,
114110
variantName = name,
115111
debug = extension.debug,
116-
cliExecutable = cliExecutable,
117112
sentryProperties = sentryProps,
118113
autoUploadNativeSymbols = extension.autoUploadNativeSymbols,
119114
includeNativeSources = extension.includeNativeSources,

plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryUploadProguardMappingsTask.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ abstract class SentryUploadProguardMappingsTask : SentryCliExecTask() {
8989
extension: SentryPluginExtension,
9090
sentryTelemetryProvider: Provider<SentryTelemetryService>?,
9191
debug: Property<Boolean>,
92-
cliExecutable: Provider<String>,
9392
sentryProperties: String?,
9493
generateUuidTask: Provider<SentryGenerateProguardUuidTask>,
9594
mappingFiles: Provider<FileCollection>,
@@ -108,7 +107,6 @@ abstract class SentryUploadProguardMappingsTask : SentryCliExecTask() {
108107
task.dependsOn(generateUuidTask)
109108
task.workingDir(project.rootDir)
110109
task.debug.set(debug)
111-
task.cliExecutable.set(cliExecutable)
112110
task.sentryProperties.set(sentryProperties?.let { file -> project.file(file) })
113111
task.uuidFile.set(generateUuidTask.flatMap { it.outputFile })
114112
task.mappingsFiles = mappingFiles

0 commit comments

Comments
 (0)