Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion e2eTest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,24 @@ tasks.register<Test>("e2eTest") {
classpath = debug.classpath

doNotTrackState("Always run e2e emulator tests to mirror Android Studio")
}
}

// Give this module friend access to `:auth` internals, so the e2e tests can drive test
// seams that are `internal` rather than forcing those seams to stay public API.
//
// Two things here are deliberate and should not be simplified:
//
// 1. `libraries` is filtered instead of naming the jar it resolves to. That jar lives under
// AGP's `intermediates` tree, which is an implementation detail and moves on an AGP bump.
// 2. `rootProject.layout.projectDirectory` rather than `project(":auth").layout.buildDirectory`.
// The latter works today, but it is cross-project model access and breaks under project
// isolation.
//
// Appending `-Xfriend-paths` to `compilerOptions.freeCompilerArgs` does not work: KGP
// generates that flag itself from the typed `friendPaths` property, so a hand-appended copy
// is ignored. Pointing at `auth/build/tmp/kotlin-classes/debug` does not work either, because
// `:e2eTest` never sees that directory.
val authBuildDir = rootProject.layout.projectDirectory.dir("auth/build").asFile.absolutePath
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
friendPaths.from(libraries.filter { it.absolutePath.startsWith(authBuildDir) })
}
Comment on lines +105 to +108

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using rootProject in a subproject's build script violates Gradle's Project Isolation principles, as it couples the subproject directly to the root project model at configuration time. Instead, you can navigate relatively using the current project's layout.projectDirectory.\n\nAdditionally, using startsWith on absolute path strings can lead to false positives if there are other directories with similar prefixes (e.g., auth/build-cache). Using Kotlin's File.startsWith(File) extension is safer as it compares actual path components.

val authBuildDir = layout.projectDirectory.dir("../auth/build").asFile\ntasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {\n    friendPaths.from(libraries.filter { it.startsWith(authBuildDir) })\n}

Loading