Skip to content

Fix configuration cache compatibility#18

Merged
nimeacuerdo merged 3 commits intomainfrom
ANDROID-17457
Feb 24, 2026
Merged

Fix configuration cache compatibility#18
nimeacuerdo merged 3 commits intomainfrom
ANDROID-17457

Conversation

@nimeacuerdo
Copy link
Contributor

@nimeacuerdo nimeacuerdo commented Feb 23, 2026

🎟️ Jira ticket

ANDROID-17457

🥅 What's the goal?

Fix configuration cache compatibility

🚧 How do we do it?

  • Remove all Task.project access at execution time, which is forbidden under Gradle's configuration cache
  • Capture project-derived values (applicationId, adbExecutablePath, isRecordMode, goldenSnapshotsSourcePath, ProviderFactory) at configuration time and pass them into execution closures
  • Refactor DeviceFileManager to accept pre-resolved values instead of deriving them from testTask.project
  • Move doFirst/doLast work directly onto the DeviceProviderInstrumentTestTask to avoid serializing task references in closures
  • Keep empty androidSnaptestingBefore*/androidSnaptestingAfter* tasks as dependency anchors for CI scripts
  • Remove onTaskCompleted listener (used BuildEventListenerRegistryInternal and project.provider — both config-cache incompatible)

📘 Documentation changes?

  • No docs to update nor create

🧪 How can I test this?

@nimeacuerdo nimeacuerdo marked this pull request as ready for review February 23, 2026 11:56
Copy link
Contributor

@jeprubio jeprubio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the Android Snaptesting Gradle plugin to be compatible with Gradle Configuration Cache by avoiding execution-time Task.project access and by precomputing project/variant-derived values during configuration.

Changes:

  • Refactors DeviceFileManager to accept pre-resolved applicationId, adbExecutablePath, and ProviderFactory instead of deriving them from testTask.project.
  • Reworks plugin wiring so snapshot cleanup and report generation are attached directly to DeviceProviderInstrumentTestTask actions, and removes the task-completion listener.
  • Keeps empty androidSnaptestingBefore* / androidSnaptestingAfter* tasks as CI dependency anchors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
include-build/gradle-plugin/src/main/java/com/telefonica/androidsnaptesting/DeviceFileManager.kt Removes project/AGP lookups from DeviceFileManager and uses injected/captured values at runtime.
include-build/gradle-plugin/src/main/java/com/telefonica/androidsnaptesting/AndroidSnaptestingPlugin.kt Rewires task actions to avoid config-cache-incompatible listeners and execution-time project access, and keeps CI anchor tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 37 to 42
@Suppress("DEPRECATION")
val testedVariant = extension.testVariants
.firstOrNull { it.name == deviceProviderTask.variantName }
?: throw RuntimeException("TestVariant not found for ${deviceProviderTask.variantName}")
val applicationIdProvider = providerFactory.provider { testedVariant.applicationId }
val adbExecutablePath = extension.adbExecutable.absolutePath
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applicationIdProvider is evaluated during task execution via applicationIdProvider.get() in doFirst/doLast, and its supplier reads testedVariant.applicationId. This reintroduces execution-time access to an AGP variant object (and potentially project-backed state), which is typically incompatible with Gradle configuration cache and undermines the PR goal. Prefer resolving applicationId to a plain String during configuration (inside afterEvaluate) and capture that value in the task actions, or otherwise ensure the provider does not touch AGP variant/project state at execution time.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be a real issue, because gradle is reporting that the configuration cache is being used in the local tests

Comment on lines 61 to 70
deviceProviderTask.doLast {
(it as DeviceProviderInstrumentTestTask)
.afterExecution(
applicationId = applicationIdProvider.get(),
adbExecutablePath = adbExecutablePath,
providerFactory = providerFactory,
isRecordMode = isRecordMode,
goldenSnapshotsSourcePath = goldenSnapshotsSourcePath,
)
}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afterExecution() is now only invoked from a doLast action on DeviceProviderInstrumentTestTask. If the instrumented test task fails (e.g., test failures / snapshot mismatches), Gradle typically aborts remaining task actions, so this doLast may never run and reports/snapshot pulls won’t be generated. Previously the completion listener ensured the post-processing ran even when the task failed. Consider running the post-processing from a finalizer task that always executes (e.g., a non-empty androidSnaptestingAfter* task wired via finalizedBy) or another config-cache-safe mechanism that guarantees execution on failure.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewing this...

Copy link
Contributor Author

@nimeacuerdo nimeacuerdo Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be fixed at aeb1d53, according to tests done in android-messenger and SmartWifi, where reports are successfully generated now

no copilot tokens left, btw 😅

@nimeacuerdo nimeacuerdo marked this pull request as draft February 23, 2026 16:19
@nimeacuerdo nimeacuerdo marked this pull request as draft February 23, 2026 16:19
@nimeacuerdo nimeacuerdo marked this pull request as ready for review February 24, 2026 12:31
Copy link
Contributor

@jeslat jeslat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good job

@nimeacuerdo nimeacuerdo added the enhancement New feature or request label Feb 24, 2026
@nimeacuerdo nimeacuerdo merged commit f59a64e into main Feb 24, 2026
3 checks passed
@nimeacuerdo nimeacuerdo deleted the ANDROID-17457 branch February 24, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants