Converting to DSL Kotlin scripts and Apollo Errors on Compile

Project compile fine in groovy and when I converted to DSL it fails to build due to Apollo

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not create task ':app:generateServiceApolloSources'.
   > Apollo: specify 'packageName':
     apollo {
       packageName.set("com.example")
       
       // Alternatively, if you're migrating from 2.x, you can keep the 2.x   
       // behaviour with `packageNamesFromFilePaths()`: 
       packageNamesFromFilePaths()
     }

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring project ':app'.
	at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
	at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:51)
	at org.gradle.configuration.project.LifecycleProjectEvaluator$NotifyAfterEvaluate.run(LifecycleProjectEvaluator.java:195)
	 ...

My script before had this

   apollo {
        service("apollo") {
            packageNamesFromFilePaths("com.mine.android.apollo")
            sourceFolder.set("com/mine/android/apollo")
            customTypeMapping = [
                    "Decimal" : "kotlin.Double"
            ]
        }
    }

Now it has this after converting to DSL

apollo {
     service("apollo") {
        packageNamesFromFilePaths("com.mine.android.apollo")
        sourceFolder.set("com/mine/android/apollo")
        customTypeMapping.set(
            mapOf("Decimal" to "kotlin.Double")
        )
    }
}

And this fails the build with the above

Please help. not familiar with Apollo and documentation is not good and does not work.

Hi :wave: Can you provide more details in what context the apollo {} block is called?

You’ll need to add it at the top level of your build.gradle.kts file or else the plugin will try to register its tasks before your configuration is taken into account. I suspect right now the apollo {} block is called a little too late, maybe in afterEvaluate {} or something similar?

Yeah something you don’t show in your example, where to put the Apollo block. Ours is in the Android of our app module build.gradle.kts. I did find something that did work.

`

apollo {
        service("apollo") {
            schemaFile.set(file("src/main/graphql/com/mine/android/apollo/schema.json"))
            packageName.set("com.mine.android.apollo")
        }
}

`

Thanks for the follow up! Glad it worked ultimately :). Do you mind sharing what page of the documentation/sample you were looking at? I’ll make this more explicit.

1 Like