:wave: I'm seeing some `generateXxxApolloSources` ...
# apollo-kotlin
w
👋 I'm seeing some
generateXxxApolloSources
tasks created during configuration time. It happens when calling
registerJavaGeneratingTask
, I think specifically in the
outputDir.get()
part — the
outputDir
is a provider based on
outputDir
argument of
DefaultDirectoryConnection
which in turn comes from
sourcesBaseTaskProvider.flatMap { }
. So in the end, the directory property is resolved which causes the task to be resolved/created, if I read that right? Or it's a misconfiguration on our end (because e.g. the variants shouldn't be resolved in the first place, or we may be doing something with Apollo tasks) or something else entirely?
There is a chance we're doing some
variants.all { }
or equivalent somewhere, I just want to make sure that it's possible to not have these tasks created during configuration
m
Sorry I missed your message earlier today. That’s interesting. I’m still using good old non-lazy
registerJavaGeneratingTask()
because of https://issuetracker.google.com/u/1/issues/382215754 I have resisted a long time moving away from this because it’s so simple compared to the new way of doing things but looks like it’s time to finally make peace with this…
Out of curiosity, how bad is the eager task creation? It’s not thousands of tasks and I wouldn’t expect the JVM to choke on creating a few classes but maybe there’s more to it.
w
No worries! So the
registerJavaGeneratingTask
is somewhat lazy — at least the task passed is a provider, the issue is only with the output file. Which API is the new way, is it
addGeneratedSourceDirectory
? I'll be honest I don't even know what the code that I linked to does 😄 > Out of curiosity, how bad is the eager task creation? It's not bad, we have a handful of modules with Apollo so that's several tasks created. I was just going issue by issue looking to reduce configuration time (1k+ tasks created now) and I noticed Apollo.
👍 1
But the more I'm looking at this, the more I have a feeling we're doing something wrong and the variant is resolved non-lazily somewhere else. Apollo does
extension.libraryVariants.configureEach
which I suppose should be lazy enough blob thinking fast Also I didn't get to the bottom of where the
outputDir
of the
sourceBaseTaskProvider
is set in the first place, so thought that maybe the value is hardcoded anyway and could be passed as a
File
. But I can't even read AGP sources enough to know it wouldn't break caching or something like that
m
Which API is the new way, is it
addGeneratedSourceDirectory
?
Yup, exactly
So the
registerJavaGeneratingTask
is somewhat lazy — at least the task passed is a provider, the issue is only with the output file.
Right,
outputDir.get()
might be an issue still and I think we're always passing the same value there: https://github.com/apollographql/apollo-kotlin/blob/7668a302eb5c62ca1d3e423ccfefa1[…]tlin/com/apollographql/apollo/gradle/internal/BuildDirLayout.kt
Copy code
internal fun outputDir(project: Project, service: Service): Provider<Directory> {
    return project.layout.buildDirectory.dir(
        "generated/source/apollo/${service.name}"
    )
  }
We might as well hardcode this, I think it would remove your issue
w
I see it's merged, thanks a lot! 🙇
I hope it doesn't break anything for anyone 🤞
m
It's looking good!