Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ private fun IrTask.register(): FunSpec {
.addCode(
buildCodeBlock {
if (isolationOptions != null) {
add("var configuration = this@%L.configurations.findByName(%S)\n", registerName(), isolationOptions.configurationName)
add("if (configuration == null) {\n")
add("val configurationProvider =\n")
withIndent {
add("configuration = this@%L.configurations.create(%S)\n", registerName(), isolationOptions.configurationName)
add("configuration.dependencies.add(dependencies.create(%S))\n", isolationOptions.coordinates)
add("this@%L.configurations.findByName(%S)\n", registerName(), isolationOptions.configurationName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, findByName() is not lazy either, you'll have to do the big try/catch dance around named().

Given that this code is only called when the task itself is configured and that if the task is configured, I would expect it to run, I'm not 100% sure what there is to gain here but if we really want to make things lazy, let's do this consistently?

Copy link
Copy Markdown
Contributor Author

@simonlebras simonlebras Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right 👍 I've updated the codegen with your suggestion.

I should have added more details in the description.

  • when using androidx.lint:lint-gradle, lint is complaining about generated code because of create calls, which requires using lint-baseline.
  • If the task is never executed, configuration is never realized and stays lazy, even if the task is configured.

I do agree that the gain is small, so feel free to close the PR if you feel it's not worth it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still mad that creating a Configuration is costly. It should really be a simple object, having to make everyone go through the hoops of creating lambdas is meh...
But the reality of today is that Provider<Configuration> is 1/10 of the RAM usage of a Configuration so let's go with that 👍
Thanks for the contribution 🙏

add("?: this@%L.configurations.register(%S) {\n", registerName(), isolationOptions.configurationName)
withIndent {
add("it.dependencies.add(dependencies.create(%S))\n", isolationOptions.coordinates)
}
add("}\n")
}
add("}\n")
add(
"gradle.sharedServices.registerIfAbsent(\"gratatouille\", %T::class.java) {}\n",
ClassName(gratatouilleWiringPackageName, "GratatouilleBuildService")
Expand All @@ -90,7 +92,7 @@ private fun IrTask.register(): FunSpec {
add("it.group = ${taskGroup}\n")
add("it.description = ${taskDescription}\n")
if (isolationOptions != null) {
add("it.${classpath}.from(configuration)\n")
add("it.${classpath}.from(configurationProvider)\n")
}
add("if (extraClasspath != null) {\n")
withIndent {
Expand Down