~This is quite odd, but by doing <this exact diff>...
# apollo-kotlin
s
This is quite odd, but by doing this exact diff on my project, so moving the configuration of Apollo's Service through an Action to my own convention plugin which applies the apollo gradle plugin, and tries to configure the
com.apollographql.apollo.gradle.api.ApolloExtension
in there.
When I then try to run
./gradlew download[Service]ApolloSchemaFromIntrospection
I get a crash and the download does not happen.
More info plus the error message inside thread ๐Ÿงต edit: Just me being a gradle dingus, nevermind this. The thread will contain my ramblings forever
๐Ÿ’™ 2
๐Ÿ˜„ 2
This may again have something specific to do with the DAGP project, so I am sharing this here just to see if there's anything obvious. If not, I don't think we should dig into this. I can just do things "the normal way" and configure everything in my module as I did before, so just revert this commit.
First there are some warnings about cc:
Copy code
42 problems were found storing the configuration cache, 8 of which seem unique.
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.groovy.scripts.internal.DefaultScriptCompilationHandler$ScriptClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.initialization.MixInLegacyTypesClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.internal.classloader.CachingClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.internal.classloader.FilteringClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.internal.classloader.VisitableURLClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
- Task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: cannot serialize object of type 'org.gradle.internal.event.AnonymousListenerBroadcast', a subtype of 'org.gradle.internal.event.ListenerBroadcast', as these are not supported with the configuration cache.
See <https://docs.gradle.org/8.10.2/userguide/configuration_cache.html#config_cache:requirements:disallowed_types>
Then the exception:
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache state could not be cached: field `external` of `com.autonomousapps.internal.artifacts.Publisher` bean found in field `storage` of `org.gradle.internal.extensibility.DefaultExtraPropertiesExtension` bean found in field `extension` of `org.gradle.internal.extensibility.ExtensionsStorage$ExtensionHolder` bean found in field `extensions` of `org.gradle.internal.extensibility.ExtensionsStorage` bean found in field `extensionsStorage` of `org.gradle.internal.extensibility.DefaultConvention` bean found in field `extensions` of `org.jetbrains.kotlin.gradle.dsl.DefaultToolchainSupport` bean found in field `this$0` of `org.jetbrains.kotlin.gradle.dsl.DefaultToolchainSupport$wireToolchainToTasks$1` bean found in field `val$action` of `org.gradle.api.internal.plugins.DefaultPluginContainer$2` bean found in field `this$1` of `org.gradle.api.internal.plugins.DefaultPluginContainer$2$1` bean found in field `val$spec` of `org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$1` bean found in field `spec` of `org.gradle.api.internal.collections.CollectionFilter` bean found in field `this$0` of `org.gradle.api.internal.collections.CollectionFilter$1` bean found in field `multipleActions` of `org.gradle.internal.ImmutableActionSet$SetWithManyActions` bean found in field `addActions` of `org.gradle.api.internal.collections.DefaultCollectionEventRegister` bean found in field `eventRegister` of `org.gradle.api.internal.plugins.DefaultPluginContainer` bean found in field `this$0` of `org.gradle.api.internal.plugins.DefaultPluginContainer$2` bean found in field `val$action` of `org.gradle.internal.code.DefaultUserCodeApplicationContext$CurrentApplication$1` bean found in field `delegate` of `org.gradle.api.internal.DefaultCollectionCallbackActionDecorator$BuildOperationEmittingAction` bean found in field `actions` of `org.gradle.internal.ImmutableActionSet$SetWithFewActions` bean found in field `addActions` of `org.gradle.api.internal.collections.DefaultCollectionEventRegister` bean found in field `eventRegister` of `org.gradle.api.internal.DefaultDomainObjectSet` bean found in field `idMappings` of `org.gradle.api.internal.plugins.DefaultPluginManager` bean found in field `pluginManager` of `com.hedvig.android.ApolloSchemaHandler` bean found in field `this$0` of `com.hedvig.android.ApolloSchemaHandler$configure$2$1` bean found in field `action` of `org.gradle.api.internal.AbstractTask$TaskActionWrapper` bean found in field `actions` of task `:apollo-octopus-public:downloadOctopusApolloSchemaFromIntrospection` of type `com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask`: error writing value of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer$NamedDomainObjectCreatingProvider'
> Resolving dependency configuration 'projectHealthElements' is not allowed as it is defined as 'canBeResolved=false'.
Instead, a resolvable ('canBeResolved=true') dependency configuration that extends 'projectHealthElements' should be resolved.
Now, the weird part is that this only happens to me when I run that task, when I run other tasks like building the app, or even
./gradlew buildHealth
which comes from that plugin, it works just fine. Anything that stands out from a first glance?
With that commit reverted, running the same
./gradlew download[Service]ApolloSchemaFromIntrospection
just runs everything smoothly, not even giving me any warnings about CC ๐Ÿ˜„
Trying this also results in the same error FWIW. I thought perhaps something to do with how I use an Action there, but does not look like it. All that
apolloSchema()
calls is:
Copy code
pluginManager.apply(libs.plugins.apollo.get().pluginId)
project.tasks.withType<com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask>().configureEach {
  doLast {
    val schemaFile = outputFile.get().asFile
    val schemaText = schemaFile.readText()
    val convertedSchema = schemaText.performClientSideChanges()
    schemaFile.writeText(convertedSchema)
  }
}
So I apply the apollo plugin and just configure a task.
And super interestingly, removing the
Copy code
project.tasks.withType<com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask>().configureEach {
  doLast {
    val schemaFile = outputFile.get().asFile
    val schemaText = schemaFile.readText()
    val convertedSchema = schemaText.performClientSideChanges()
    schemaFile.writeText(convertedSchema)
  }
}
part also fixes this! Hmmmm what could this be then ๐Ÿ˜„
Please do excuse me rambling about learning what gradle even is here ๐Ÿ˜‚ My inexperience with it is really showing, and somehow it always surfaces when I am doing apollo-kotlin adjacent stuff, but it turns out to never be apollo-kotlin's fault ๐Ÿ˜‚ Replacing my
Copy code
internal abstract class ApolloSchemaHandler @Inject constructor(
  private val project: Project,
  private val pluginManager: PluginManager,
  private val libs: LibrariesForLibs,
) {
  fun configure() {
...
With just
Copy code
internal abstract class ApolloSchemaHandler {
  fun configure(project: Project) {
    val libs = project...
    val pluginManager = project.pluginManager
    ...
Where I pass the
project
myself in this function instead of through the `newInstance<ApolloSchemaHandler>(...here) Then it also just works without any problems. So looks like I should not be passing my project like that. I think I saw other people do it and I thought it'd be fine ๐Ÿคท
m
Apologies for the late response and thanks for the deep dive ๐Ÿ™‚ !
Configuration cache has its ways blob upside down
It's quite the internal journey to understand what's going on...
In your particular case, the fact that removing the below makes everything work is interesting
Copy code
project.tasks.withType<com.apollographql.apollo.gradle.internal.ApolloDownloadSchemaTask>().configureEach {
  doLast {
    val schemaFile = outputFile.get().asFile
    val schemaText = schemaFile.readText()
    val convertedSchema = schemaText.performClientSideChanges()
    schemaFile.writeText(convertedSchema)
  }
}
I'd say something up there in the
doLast {}
lambda is capturing a reference to something that cannot be serialized to the CC. It's very easy to end up in situation like this with
doLast {}
lambdas
If you wanted to do things super idiomatically, I guess, you could extract your client side transformation to a separate
PatchSchema
task and connect the
apolloDownloadTask.output
to your
PatchSchema.input
and
PatchSchema.output
to
ApolloService.schemaFiles
But if everything is working now well, not need to fix it ๐Ÿ˜„