@@ -37,13 +37,8 @@ import org.gradle.kotlin.dsl.register
3737 */
3838abstract class CopyGoogleServicesPlugin : Plugin <Project > {
3939 override fun apply (project : Project ) {
40- val sourcePath =
41- System .getenv(" FIREBASE_GOOGLE_SERVICES_PATH" ) ? : " ${project.rootDir} /google-services.json"
40+ val sourcePath = getSourcePath(project)
4241 val copyRootGoogleServices = registerCopyRootGoogleServicesTask(project, sourcePath)
43- if (! File (project.projectDir, " google-services.json" ).exists() && ! File (sourcePath).exists()) {
44- val createDummyGoogleServices = registerDummyGoogleServicesTask(project, sourcePath)
45- copyRootGoogleServices.dependsOn(createDummyGoogleServices)
46- }
4742
4843 project.allprojects {
4944 // fixes dependencies with gradle tasks that do not properly dependOn `preBuild`
@@ -66,15 +61,6 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
6661 return gradle.startParameter.taskNames.any { testTasks.any(it::contains) }
6762 }
6863
69- private fun registerDummyGoogleServicesTask (project : Project , path : String ) =
70- project.tasks.register<Copy >(" copyDummyGoogleServices" ) {
71- logger.warn(" Google services file not found, using fallback" )
72-
73- from(" ${project.rootDir} /plugins/resources/dummy-google-services.json" )
74- into(path)
75- rename { " google-services.json" }
76- }
77-
7864 private fun registerCopyRootGoogleServicesTask (project : Project , path : String ) =
7965 project.tasks.register<Copy >(" copyRootGoogleServices" ) {
8066 val library = project.extensions.getByType<BaseExtension >()
@@ -107,4 +93,13 @@ abstract class CopyGoogleServicesPlugin : Plugin<Project> {
10793
10894 return ! file.readText().contains(targetPackageLine)
10995 }
96+
97+ private fun getSourcePath (project : Project ): String {
98+ val path =
99+ System .getenv(" FIREBASE_GOOGLE_SERVICES_PATH" ) ? : " ${project.rootDir} /google-services.json"
100+ if (File (project.projectDir, " google-services.json" ).exists() || File (path).exists()) {
101+ return path
102+ }
103+ return " ${project.rootDir} /plugins/resources/dummy-google-services.json"
104+ }
110105}
0 commit comments