Skip to content
Open
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
6 changes: 3 additions & 3 deletions docs/PLUGIN_AUTHORING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ plugins {
}
```

CoGo injects `LogSenderPlugin` (via its build init script) into every module; that
plugin references AGP's `ApplicationVariant` and is loaded from the root buildscript
classpath, so a root without AGP fails configuration with
CoGo injects `LogSenderPlugin` (via its build init script) into every Android application
module; that plugin references AGP's `ApplicationVariant` and is loaded from the root
buildscript classpath, so a root without AGP fails configuration with
`NoClassDefFoundError: com/android/build/api/variant/ApplicationVariant`.

> The in-app plugin-project detector still recognizes a project by a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,13 @@ class AndroidIDEGradlePlugin : Plugin<Project> {
}

target.run {
val isLogSenderEnabled = findProperty(PROPERTY_LOG_SENDER_ENABLED) == "true"
if (isLogSenderEnabled) {
pluginManager.apply(LogSenderPlugin::class.java)
}

val isJdwpEnabled = findProperty(PROPERTY_JDWP_ENABLED) == "true"
if (isJdwpEnabled) {
pluginManager.apply(JdwpPlugin::class.java)
}

val isProfileableEnabled = findProperty(PROPERTY_PROFILEABLE_ENABLED) == "true"
if (isProfileableEnabled) {
pluginManager.apply(ProfilerPlugin::class.java)
}

val isQuickBuildEnabled = findProperty(PROPERTY_QUICK_BUILD_ENABLED) == "true"
if (isQuickBuildEnabled) {
// By name, not ::class: Quick Build classes load (and touch newer AGP APIs)
// only when the property enables them - see QUICK_BUILD_PLUGIN_CLASS.
pluginManager.apply(Class.forName(QUICK_BUILD_PLUGIN_CLASS))
// Gradle decorates a plugin class before calling apply(), which resolves every type in
// its method signatures (compiled lambdas included). Each sub-plugin carries AGP types
// there, so on a project without AGP (a build-logic java-library in an included build)
// decoration throws before the sub-plugin's own APP_PLUGIN guard can decline
// (ADFA-6110). Check here, before any sub-plugin class is handed to Gradle.
if (plugins.hasPlugin(APP_PLUGIN)) {
applyApplicationPlugins()
}

tasks.configureEach { task ->
Expand All @@ -83,4 +70,28 @@ class AndroidIDEGradlePlugin : Plugin<Project> {
}
}
}

private fun Project.applyApplicationPlugins() {
val isLogSenderEnabled = findProperty(PROPERTY_LOG_SENDER_ENABLED) == "true"
if (isLogSenderEnabled) {
pluginManager.apply(LogSenderPlugin::class.java)
}

val isJdwpEnabled = findProperty(PROPERTY_JDWP_ENABLED) == "true"
if (isJdwpEnabled) {
pluginManager.apply(JdwpPlugin::class.java)
}

val isProfileableEnabled = findProperty(PROPERTY_PROFILEABLE_ENABLED) == "true"
if (isProfileableEnabled) {
pluginManager.apply(ProfilerPlugin::class.java)
}

val isQuickBuildEnabled = findProperty(PROPERTY_QUICK_BUILD_ENABLED) == "true"
if (isQuickBuildEnabled) {
// By name, not ::class: Quick Build classes load (and touch newer AGP APIs)
// only when the property enables them - see QUICK_BUILD_PLUGIN_CLASS.
pluginManager.apply(Class.forName(QUICK_BUILD_PLUGIN_CLASS))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,59 @@ class AndroidIDEInitScriptPluginTest {
assertThat(result.output).contains("Build directory of project ':' relocated to $expected")
}

/** ADFA-6110: a sub-plugin must not reach a project without AGP, here a build-logic java-library. */
@ParameterizedTest
@ValueSource(
strings = [
GradlePluginConfig.PROPERTY_LOG_SENDER_ENABLED,
GradlePluginConfig.PROPERTY_JDWP_ENABLED,
GradlePluginConfig.PROPERTY_PROFILEABLE_ENABLED,
GradlePluginConfig.PROPERTY_QUICK_BUILD_ENABLED,
],
)
fun `test sub-plugin leaves a non-Android project in an included build alone`(
enabledProperty: String,
@TempDir dir: File,
) {
val project = File(dir, "composite").apply { mkdirs() }
File(project, "settings.gradle.kts").writeText("rootProject.name = \"composite\"\nincludeBuild(\"lib\")\n")
File(project, "build.gradle.kts").writeText("")
val lib = File(project, "lib").apply { mkdirs() }
File(lib, "settings.gradle.kts").writeText("rootProject.name = \"lib\"\ninclude(\"common\")\n")
File(lib, "build.gradle.kts").writeText("")
val common = File(lib, "common").apply { mkdirs() }
File(common, "build.gradle.kts").writeText("plugins { `java-library` }\n")
val aar = File(dir, "dummy.aar").apply { writeText("aar") }

val result =
buildProject(
task = ":lib:common:help",
projectDir = project.toPath(),
configureArgs = {
it += "-P$enabledProperty=true"
// Read only by the sub-plugin they belong to; set both so any one can apply.
it += "-P${GradlePluginConfig.PROPERTY_LOG_SENDER_AAR}=${aar.absolutePath}"
it += "-P${GradlePluginConfig.PROPERTY_QUICK_BUILD_RUNTIME_AAR}=${aar.absolutePath}"
},
)

// Proves the IDE plugin reached the non-Android project, so the build passing means
// the sub-plugin was declined rather than never offered.
assertThat(result.output).contains("Applying AndroidIDEGradlePlugin to project ':common'")
}

/** The ADFA-6110 gate must still let sub-plugins through on an Android application module. */
@Test
fun `test sub-plugin still applies to an Android application module`() {
val result =
buildProject(configureArgs = {
it += "-P${GradlePluginConfig.PROPERTY_PROFILEABLE_ENABLED}=true"
it += "--info"
})

assertThat(result.output).contains("Applying ProfilerPlugin to project ':app'")
}

@Test
fun `test build output stays put by default`() {
val result = buildProject(configureArgs = { it += "--info" })
Expand Down
2 changes: 1 addition & 1 deletion quickbuild/docs/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ flowchart TB
classDef ext stroke-dasharray: 6 4,stroke-width:1.5px
```

- Applied by `AndroidIDEGradlePlugin` when the `PROPERTY_QUICK_BUILD_ENABLED` property is set, and only to **debuggable application variants** (`variant.debuggable`, read in `onVariants`).
- Applied by `AndroidIDEGradlePlugin` when the `PROPERTY_QUICK_BUILD_ENABLED` property is set and the module applies `com.android.application`, and only to **debuggable application variants** (`variant.debuggable`, read in `onVariants`).
- Fails the build immediately if `-Pcotg.quickbuild.runtimeAar` is missing or does not point at a file. The runtime AAR is added to the variant's **runtime** configuration only, never the compile classpath.
- Compose is detected in `finalizeDsl`, from either `buildFeatures.compose` or the `org.jetbrains.kotlin.plugin.compose` plugin, and reported to the daemon through `setup.json`.

Expand Down
Loading