Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when KSP plugin applied before AGP #2183

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ import java.util.concurrent.Callable
@Suppress("UnstableApiUsage") // some android APIs are unsable.
object AndroidPluginIntegration {

private val agpPluginIds = listOf("com.android.application", "com.android.library", "com.android.dynamic-feature")

fun forEachAndroidSourceSet(project: Project, onSourceSet: (String) -> Unit) {
agpPluginIds.forEach { agpPluginId ->
project.pluginManager.withPlugin(agpPluginId) {
// for android apps, we need a configuration per source set
decorateAndroidExtension(project, onSourceSet)
}
project.pluginManager.withPlugin("com.android.base") {
// for android modules, we need a configuration per source set
decorateAndroidExtension(project, onSourceSet)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,16 @@ class GradleCompilationTest {
)
testRule.runner().withArguments(":app:assembleDebug").build()
}

/**
* Regression test for https://github.com/google/ksp/issues/2174
*/
@Test
fun androidGradlePluginBuiltInKotlinWithKspAppliedFirst() {
testRule.setupAppAsAndroidApp(applyKspPluginFirst = true)
// Enable AGP's built-in Kotlin support for test fixtures
testRule.runner()
.withArguments("tasks", "-Pandroid.experimental.enableTestFixturesKotlinSupport=true")
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,25 @@ class KspIntegrationTestRule(
/**
* Sets up the app module as an android app, adding necessary plugin dependencies, a manifest
* file and necessary gradle configuration. If [enableAgpBuiltInKotlinSupport] is true, enable AGP's built-in Kotlin
* support instead of applying the Kotlin Android Gradle plugin.
* support instead of applying the Kotlin Android Gradle plugin. If [applyKspPluginFirst] is true, apply the KSP
* plugin first.
*/
fun setupAppAsAndroidApp(enableAgpBuiltInKotlinSupport: Boolean = false) {
fun setupAppAsAndroidApp(
enableAgpBuiltInKotlinSupport: Boolean = false,
applyKspPluginFirst: Boolean = false
) {
testProject.appModule.plugins.addAll(
listOf(
PluginDeclaration.id("com.android.application", testConfig.androidBaseVersion),
PluginDeclaration.id("com.google.devtools.ksp", testConfig.kspVersion)
)
if (applyKspPluginFirst) {
listOf(
PluginDeclaration.id("com.google.devtools.ksp", testConfig.kspVersion),
PluginDeclaration.id("com.android.application", testConfig.androidBaseVersion)
)
} else {
listOf(
PluginDeclaration.id("com.android.application", testConfig.androidBaseVersion),
PluginDeclaration.id("com.google.devtools.ksp", testConfig.kspVersion)
)
}
)
if (enableAgpBuiltInKotlinSupport) {
testProject.appModule
Expand Down
Loading