Skip to content

Conversation

@simonlebras
Copy link
Contributor

Use register to create configuration

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
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
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
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 🙏

@martinbonnin martinbonnin merged commit a3c400d into GradleUp:main Oct 16, 2025
1 check passed
@simonlebras simonlebras deleted the gradle-lazy branch October 16, 2025 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants