Skip to content

Commit 69351c1

Browse files
committed
Fix CopyGoogleServicesPlugin for dataconnect
A recent change to `CopyGoogleServicesPlugin.kt` in #7454 caused it to skip all of its logic if the project already had its own `google-services.json` (as firebase-dataconnect _does_). Part of this logic is to apply the `com.google.gms.google-services` Gradle plugin when running (or compiling) tests. The `firebase-dataconnect` project relied on this side effect and the changes to `CopyGoogleServicesPlugin.kt` caused this side effect to no longer happen to firebase-dataconnect, causing the following build error: ``` firebase-dataconnect/src/androidTest/kotlin/com/google/firebase/dataconnect/testutil/FirebaseAppIdTestUtil.kt:23:68 Unresolved reference 'string'. ``` The fix in this commit modifies `CopyGoogleServicesPlugin.kt` to apply the `com.google.gms.google-services` Gradle plugin just as it did before, even if the project defines its own `google-services.json`. This was probably the intended behavior all along.
1 parent 5ddcc4b commit 69351c1

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

plugins/src/main/java/com/google/firebase/gradle/plugins/CopyGoogleServicesPlugin.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.google.firebase.gradle.plugins
1818

1919
import com.android.build.gradle.BaseExtension
20-
import com.android.build.gradle.internal.tasks.factory.dependsOn
2120
import java.io.File
2221
import org.gradle.api.Plugin
2322
import org.gradle.api.Project
@@ -38,18 +37,17 @@ import org.gradle.kotlin.dsl.register
3837
abstract class CopyGoogleServicesPlugin : Plugin<Project> {
3938
override fun apply(project: Project) {
4039
if (File(project.projectDir, "google-services.json").exists()) {
41-
project.logger.warn("Google Services file already present in project, skipping copy task")
42-
return
43-
}
44-
45-
val sourcePath = getSourcePath(project)
46-
val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath)
47-
48-
project.allprojects {
49-
// fixes dependencies with gradle tasks that do not properly dependOn `preBuild`
50-
tasks.configureEach {
51-
if (name !== "copyRootGoogleServices") {
52-
dependsOn(copyRootGoogleServices)
40+
project.logger.info("Google Services file already present in project, skipping copy task")
41+
} else {
42+
val sourcePath = getSourcePath(project)
43+
val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath)
44+
45+
project.allprojects {
46+
// fixes dependencies with gradle tasks that do not properly dependOn `preBuild`
47+
tasks.configureEach {
48+
if (name !== "copyRootGoogleServices") {
49+
dependsOn(copyRootGoogleServices)
50+
}
5351
}
5452
}
5553
}

0 commit comments

Comments
 (0)